Posted by: Brian de Alwis | January 20, 2010

MacOS X Tips

I switched to using a Mac about a year and a half ago, and have accumulated a big hairy wad of hints and tips that I’ve learned over that time. It’s finally time to share.

I’m a fairly hardcore Unix hacker, and had been running 386BSD followed by NetBSD since about 1992. I love command-line interfaces, but was becoming increasingly tired and frustrated with dealing with configuring X (GNOME/KDE sadly seem as bloated as anything put out by Redmond) and dealing with the terrible UIs of typical GTK apps. With a new job requiring C# development under Windows, I no longer wanted to fight the configuration battles. I just wanted something that just worked. So I took the plunge, bought VMWare Fusion so as to run Visual Studio, and haven’t looked back.

But I’m still a Unix hacker at heart, and (from observation) not a very typical mac user. So these tips won’t be to everyone’s taste. Some of these tips will require that you use the Terminal.

[Note: I'll be editting this inline as I discover new tips.]

Transition Guides

There are a bunch of good transition guides available. Here are three that I had bookmarked:

Configuring the Interface

The mac interface is not perfect and needs tweaking.

  • I use DoubleCommand to map the mostly-useless second Alt/Option key to be a real delete. Macs confusingly call backspace “backward delete”, and the real delete as “forward delete”.
  • I use Butler as a keyboard and application launcher. I did look at QuickSilver at one point, and although I very much liked that I could reference an action to a file, I much preferred Butler’s pasteboard (clipboard) stack and viewer.
  • Drag and add /Applications to your dock as a stack to provide faster access to applications. Butler’s abbreviations are even faster though.
  • I assign several keyboard shortcuts, such as a keyboard shortcut for “zoom”. This is great as many (unfortunately not all) mac apps will intelligently zoom to take up as much space as is necessary, rather than all the space that is available (and is one of the reasons why I continue to use Safari and not Firefox). I use a similar approach to bind the “Open URL” service, and a slight variation to emulate Firefox’s type-ahead search in Safari
  • There’s nothing quite like having your Mac startup sound blare forth in a conference session. Fortunately StartupSound will nearly mute it.
  • RCDefaultApp allows viewing app settings for file types, URL schemes, etc, etc.

Many apps and system utilities support undocumented preferences.

  • As a Canadian, I like to use Canadian spellings (a strange mishmash of British -our with American -ize). Fortunately MacOS X comes to the rescue:
    $ defaults write -g NSPreferredSpellServerLanguage en_CA

    No more squiggles under “labour in the harbour prioritized”!

  • Install Secrets: this excellent tool provides a preference pane for manipulating undocumented preferences. The nicest part is that it auto-updates the known settings list from the ‘net. Some recommended settings:
    • I almost never use the Finder, but one of the annoying things is that it doesn’t show hidden dotfiles (e.g., .bashrc). Look under Finder for Show Hidden Files. With Snow Leopard, this can now be toggled using Cmd-. (Cmd-period) and Cmd-, (Cmd-comma), which is fantastic.
    • I could make myself a coffee waiting for MacOS X’s tooltips. Fortunately for my coffee habit, this is adjustable by changing System’s Tooltip Delay.
    • Set Terminal’s Make focus follow mouse for more X-style mousing; in 10.6, you can even type into the xterm when it’s not the active app!  X11.app also supports a focus-follows-mouse for X apps.
    • I add /Applications to my dock as a stack, and enable the Dock’s Highlight stack items on hover to highlight the item under the cursor.
    • I enable Finder’s Show path bar puts the full path as clickable components at the bottom of the Finder columns, and Show path in title bar does the same in the title bar.
    • I disable Finder’s Use .DS_Stores on network to prevent leaving little turds on remote mounted machines.
    • I set System’s Crash Dialog option to “Developer” to prevent all crashes being sent to Apple. I also set Show file extensions in open/save dialogs, Expand print dialog by default and Expand save dialogs by default.
    • I set Mail’s Preferred Mail Charset to UTF-8.
    • I disable Skype’s Show Splash Screen

Handy Software Utilities

  • BibDesk is a fantastic bibliography manager, and is free.
  • Skim is a fantastic PDF reader — I’ve set it as my default PDF reader instead of Preview.
  • Growl is a useful and widely-supported event notification mechanism.  It includes two amazing plugins: GrowlMail, which can show summaries of new messages, andHardwareGrowler, which provides updates of new hardware connects and disconnects.
  • Install VLC, MPlayerOSX, and Perian and you’ll be set in terms of media.  I set most media files to open in QuickTime rather than iTunes to prevent files from being automatically added to my iTunes database.
  • Ambrosia Apps has a free envelope printing dashboard widget.
  • I’ve put together two little applets to improve workflow. OpenDOI.app provides for resolving doi: URLs. PatchHacks.app provides some hacks to treat .diff and .patch files as plain text files, enabling quick-look.
  • MacOS X includes a built-in VNC viewer: /System/Library/CoreServices/Screen Sharing.app. You can open a VNC connection from the Finder’s Go → Connect to Server.

Using Spaces

I’m a big fan of virtual desktops, and fortunately switched just after the introduction of Leopard and Spaces. Otherwise I’m sure I would have hated MacOS X.

I use 6 spaces. I assign space #1 as my communication space. Space 4 is my Windows space, where I run VMs: I have VMWare Fusion set up to occupy this space. Space 6 is my Java development space. Spaces 2, 3, and 5 are my “misc” work spaces.

Use Secrets (described above) to set the Dock’s Show other spaces’ windows in Expose to 0 to disable Expose’s stupid decision to show every single window regardless of space.

An app is generally “homed” to a particular space. An app can be assigned to be in all spaces, which I do for iTunes, Skype, Adium, and BibDesk. New app windows are generally be created in that app’s homed space. But I use Terminal and Safari a lot across different spaces, and want new windows to appear on the current space. And I also often compose new messages from one of those spaces. Fortunately new windows can usually be created in the active space through some relatively boring applescripts, which I bind to hotkeys using Butler.

To create these scripts, use the AppleScript Editor.app.

To open a new Terminal window:

tell application "Terminal"
	do script ""
	activate
end tell

To open a new Safari window:

tell application "Safari"
	make new document
	activate
end tell

To open a new Firefox window:

tell application "Firefox"
 	OpenURL ""
end tell

To open a new Mail message:

tell application "Mail"
	make new outgoing message with properties {visible:true}
        -- yup, three activates are required!
	activate
	activate
	activate
end tell

Command-Line Tools

Although MacOS X incorporates many BSD commands, there are many commands unique to it with (ahem) rather unusual names.

  • The command-line bible listing command equivalents for different OS’s, including MacOS X.
  • A list of commands unique to Darwin.
  • To add passwordless sudo for your account, add a line to /etc/sudoers with:
     userid     ALL=(ALL) NOPASSWD: ALL

    where userid is your shorten account name. To find or change your account name, open System Preferences → Accounts, right click on your account and select Advanced Options...

  • To open the appropriate application for a file:
    $ open path/to/file

    To open the appropriate application for editing as a text file:

    $ open -t path/to/file

    To open a file using a particular application:

    $ open -a path/to/app path/to/file

    If the application is in /Applications, this can be shortened to simply:

    $ open -a app file

    To open the appropriate application for stdin:

    $ commands ... | open -f

    You can open a VNC session with:

    $ open vnc://hostname

    To show a file in the Finder (useful for drag’n’drop):

    $ open -R path/to/file

    And like Windows’ start command,

    $ open .

    opens the Finder on the current directory.

  • To invoke QuickLook from the command-line for a set of files:
    $ qlmanage -p files ... >/dev/null 2>&1

    The redirects are required as qlmanage(1) is overly verbose. I alias this as ‘qlook’.

  • To play an audio file, see afplay(1).
  • To eject the CDROM/DVD or a volume, use
    $ hdiutil detach

    I alias this to “eject“.

  • To get a list of the available wifi hotspots:
    $ /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -s

    I alias this too :-)

  • Equivalent to ldd(1) to show the dynamic link libraries used by an app:
    $ otool -L path/to/binary

    I alias this to ‘ldd’.

  • Early on, I experienced a problem with Firefox when switching between wifi hotspots (apparently since fixed). The solution was to flush the DNS cache by:
    $ dscacheutil -flushcache
  • I used the SSID in some of my scripts to do magical things depending on my location. To get the SSID:
    ioreg -l -n AirPortDriver | grep APCurrentSSID \
     | sed 's/^.*= "\(.*\)".*$/\1/; s/ /_/g'
  • To have a verbose boot:
    $ sudo nvram boot-args="-v"

    To restore it to the normal impassive grey spinner:

    $ sudo nvram boot-args=""
  • SleepWatcher allows running a unix command when a mac goes to sleep or wakes up, or after some amount of time of user-inactivity
  • MacFUSE for user-mode file-systems, such as sshfs.
  • PreFab Event Taps Testbench: is similar to xev(1).

Other Useful Notes/References

About these ads

Responses

  1. [...] Unix hacker on Mac? Then you might love the tips and techniques presented in this post. He really gets in there to modify things.  Not suggested reading if you haven’t used [...]

  2. Nice write-up. Just wanted to say that ‘backward delete’ and ‘forward delete’ are not really weird Mac things. Calling ‘backward delete’ ‘backspace’ is really the odd behavior. The key comes from typewriters, and would do just what it sounds like – move back a space. With early typewriters, this would allow you to strike an ‘X’ or a hyphen over whatever you needed to omit. With correcting typewriters, you would space backward, switch to correction tape, rewrite your letter (using the correction tape) and then fill in a new letter. More modern typewriters with auto correction, etc. would generally have an ‘auto correct’ key in addition to the traditional backspace.

    Anyhow, if you’re already using growl and spending a lot of time on the terminal, worth it to read up on growlnotify, which lets you send growl notifications from inside shell scripts, etc…


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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

Categories

Follow

Get every new post delivered to your Inbox.

Join 149 other followers