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.
- Change directory from file selection dialog box: Press ~ to pop-up a text box to enter a filepath.
- Cycle through an application’s windows with the same shortcut, CMD-~.
- I never, never use that yellow minimize button. Instead, I always hide with CMD-h.
- 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. - 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.)
- 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-;
- 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, oropen ~/Talks/Mytalk
for another directory. - 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 typeeject /Volume/<VolumeToEject>
. Magic! - 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 commandejectbackup
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.) - 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 deleteTo 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'
- 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
- 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 .
- 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 dosips -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.