Ordering System Preferences around.

Just a quick note: the following very useful tidbit was added to System Preferences’ AppleScript dictionary in Leopard.

tell application "System Preferences"
    activate
    reveal pane id "com.toastycode.Cuckoo"
end tell

That is, you can use reveal pane localizedName or reveal pane id bundleId to tell SysPrefs to switch to a given prefPane. This is an improvement on reveal in earlier versions of the OS, which only supported the reveal anchor someTabName in pane name phrasing, which doesn’t fly if your preference pane doesn’t have tabs. (As noted here, you can use the pseudo-anchor main on Apple’s tabless prefPanes, but I couldn’t find any kind of documentation on how to add “main” to my own prefPane.)

If you try the 10.5-style reveal pane syntax on Tiger and earlier, you’ll be rewarded with a less-than-elucidating NSReceiversCantHandleCommandScriptError. (Try saying that three times fast. Or, uh, once.)

The following AppleScript will work on all releases of Mac OS X, however:

tell application "System Preferences"
    activate
    -- works in 10.4 and 10.5
    set current pane to pane id "com.toastycode.Cuckoo"
end tell

Just thought I’d share in case there’s some other poor soul out there trying to launch a specific preference panel from AppleScript or Cocoa.


About this entry