Mac Goodness

Essential tips to increase my Mac love

Mac is the unification of Unix and an amazingly elegant user interface. Still, there are some keyboard-centric tricks that are not well documented. These are the Mac tips/tricks that bring me happiness.

  1. Change directory from file selection dialog box: Press ~ to pop-up a text box to enter a filepath.
  2. Cycle through an application’s windows with the same shortcut, CMD-~.
  3. I never, never use that yellow minimize button. Instead, I always hide with CMD-h.
  4. If you’re an emacs user, you know the vital importance of the control key. Thus, I’ve used System Preferences -> Keyboard -> Keyboard -> Modifier Keys to remap CAPS LOCK to be an additional CONTROL key. Magic!
    Now if I could only remap the stupid UK-keyboard’s plus/minus/section(!) key to be ESCAPE. Sigh.
  5. Add those missing keyboard short cuts with System Preferences -> Keyboard -> Keyboard Shortcuts. Some of my favorites
    • MS Office apps: CMD-SHIFT-V for Paste Special…
    • MS Office Powerpoint: CTRL-= for Subscript, CTRL-+ for Superscript, though first you need to add these as menu items with View -> Customise Toolbars and Menus; it doesn’t matter which menu you add them to (though Format is the obvious one).
    • MS Office aps: Auto Correct common LaTeX notation into symbols. One time, type the symbol you want (e.g. β), copy it. Under Tools->Autocorrect, enter $beta$ in the “Replace:” field, and paste the symbol into the “With:” field… et voila! The next type you type ”$beta$” it will automagically be replaced with a ”β”. Add other commonly used symbols as needed. (This also works on PC Office apps).
    • Terminal Program: CMD-LEFT and CMD-RIGHT for Select Next Tab, Select Previous Tab. (And, if you haven’t discovered the magic of Tabs in Terminal program, you’re just a CMD-t away from bliss.)
  6. Having trouble with the keyboard short cuts not working? The text of the menu item must be identical to what you enter in the keyboard shortcut dialog; note that an ellipsis (…) is not three periods (…); get an ellipses on the Mac with OPTION-;
  7. Terminal bliss. I almost never use the Finder, as the Terminal can do everything I need and faster. There are, on occasions, though, things that the Finder is better at. On those occasions I just open the directory, like open ., which gives me a finder window for the current directory in the shell, or open ~/Talks/Mytalk for another directory.
  8. Terminal bliss. I find ejecting a volume cumbersome… you have to mouse around, find the volume, click on it, hit CMD-e. Ug. Better, is just to issue the command hdiutil eject /Volume/<VolumeToEject>. Better yet, define the following alias: alias eject hdiutil eject. Then you can intuitively just type eject /Volume/<VolumeToEject>. Magic!
  9. Terminal bliss. I have a “sleepnow” alias so I don’t have to fumble for the Apple->Sleep menu nor remember to eject my backup volume:
    ejectbackup; osascript -e 'tell application "System Events" to sleep'; echo Going to sleep, please wait...
    The command ejectbackup is yet another alias for:
    if (-d '/Volumes/My Backup') hdiutil eject '/Volumes/My Backup'
    which is c-shell specific, though a bash user would want
    if [ -d '/Volumes/My Backup' ] hdiutil eject '/Volumes/My Backup'

    While this ejectbackup bit is optional, it’s handy since it ejects my Time Machine backup volume so that I can yank the USB cable just before it sleeps; otherwise, without it, you’ll wake up the Mac when you pull the cable and get pesky messages telling you to eject the USB properly. (Of course, replace ‘My Backup’ for the name of your backup volume.)

  10. Remove Apple Extended Attributes. MacOS looks like Unix, but one difference is that Apple has created extensions to record arbitrary key-value pair attributes for each file. For example, the way that your Mac knows you downloaded something from the internet is because it has added attributes with keys like “com.apple.quarantine” to flag the origin of the file. To view such attributes you need the xattr program (from e.g. here), as in
    xattr -l file.txt
    To clear one particular attributes use
    xattr -d <key> file.txt
    where <key> is “com.apple.quarantine” or whatever you want to delete

    To wipe out all attributes you have to do it one by one, ug. Here’s a one-liner to do it

    xattr --list-parseable file.txt | grep = | awk -F= '{print $1}' | xargs -I %% xattr -d %% file.txt

    and, specifically, my csh alias

    alias xattr_del_all 'xattr --list-parseable \!:1 | grep = | awk -F= '\''{print $1}'\'' | xargs -I %% xattr -d %% \!:1'

  11. Sparse Bundles for extra security. I find it handy to keep confidential information on sparse bundles protected with a password. To create one use this command

    hdiutil create -size 100m -volname PatientInfo -encryption -type SPARSEBUNDLE -fs HFS+J ~/Project/PatientInfo

    You’ll be prompted for a password, and then you’ll see that this will create a directory “PatientInfo.sparsebundle” in the Project directory. In order to open this directory you’ll have to enter the password.

    If you ever need to increase the size later, use this command

    hdiutil resize -size 200m ~/Project/PatientInfo.sparsebundle

    To later change the password, use

    hdiutil chpass ~/Project/PatientInfo.sparsebundle

  12. Reunite resource fork on un-archiving, OR, how to avoid __MACOS folders. Mac OS files have a data and resource fork, where the resource fork has information metadata like file creation and modification time. Whenever you unzip a .zip file on the command line that was created on the Mac, you’ll find a __MACOS folder gets created which which contains resource for information in separate ._* files, and they can generally be safely deleted. But if you want to reunite the resource fork with each file, use ditto, like ditto -xk <<ARCHIVE.ZIP>> <<TargetDirectory>>, for example
    ditto -xk Archive.zip .
  13. Resize images. Modern digital cameras create gigantic image files, not great for sharing. While there are variety of ways to resize images on the command line (e.g. with ImageMagick) I was amazed to learn that there’s a tool built right in to Mac OS to do this. The sips command is a “scriptable image processing system”, and to resize images just do

    sips -Z 1024 *.JPG

    but note that this resizes in place, i.e. writes over the existing image. Here, 1024 specifies the maximal dimension the resized images have.

3 thoughts on “Mac Goodness

  1. Pingback: Make Word act like Emacs | NISOx Blog
  2. Pingback: Mac Goodness (2) | NISOx
  3. Pingback: Mac Goodness (3) | NISOx

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s