AppleScript: Change Spotlight Keyboard Shortcut

One of the greatest things about Mac OS X is the availability of an endless number of small shareware apps and utilities that improve your life in some way. One such utility that I simply cannot live without is X-Tunes.

VESPA It’s my industrial strength hair dryer, and I can’t live without it.

X-Tunes provides “a virtual remote control for iTunes when a key combination is pressed”. What that means is that I can be doing anything in any application, and if the current song playing on my iTunes isn’t something I want to listen to, I don’t have to stop what I’m doing and switch over to iTunes, find the window and click the next button, and then switch back to what I was doing.

Instead, X-Tunes allows you to configure a keyboard shortcut that will activate a transparent iTunes remote control on the center of your main display. The remote offers all of the most important controls (play, pause, next, volume) and is only active as long as you hold down the keyboard combination. When you release, the remote quickly fades away, and you are automatically left right back where you were before you went to change tunes. It’s fabulous dahling.

So the keyboard combination is configurable, but by default, it’s command-space. With Mac OS X 10.4 Tiger, Spotlight now uses this exact keyboard command for a very similarly-behaved spotlight popup search bar.

Well, after roughly two years of using command-space to activate an iTunes remote (which I do far more often than I search using Spotlight), I simply can’t change my habits… I can’t give up command-space for activating X-Tunes.

Happily, the Spotlight keyboard shortcut is also configurable, so I can just change the Spotlight keyboard shortcut to something else… like, say, command-F1.

Sadly, whenever I change the Spotlight keybard shortcut, it returns to the default command-space the next time I reboot. :( I haven’t done any research into this to see if this is a common bug, or if it’s something unique to my (lovely, keyboard-illuminated) PowerBook…

…But I have done something about it.

Here’s an Apple script that uses Apple’s GUI Scripting features to change the Spotlight keyboard shortcut from command-space to command-F1. I’ve set this script up as a startup item by dragging it into my list of Startup Items in System Preferences -> Accounts - > Startup Items.

Open “Change Spotlight Keyboard Sortcut.scpt” in a Script Editor window


tell application "System Preferences"
    activate
    set current pane to pane "Spotlight"
    tell application "System Events"
        try
            tell application "System Events"
                tell application process "System Preferences"
                    activate
                    tell window "Spotlight"
                        tell combo box 1
                            set it's value to "F1"
                        end tell
                    end tell
                end tell
            end tell
            tell application "System Preferences" to close the first window
        on error
            tell application "System Preferences"
                activate
                set current pane to pane "com.apple.preference.universalaccess"
                display dialog "UI element scripting is not enabled. Check \"Enable access for assistive devices\""
            end tell
        end try
    end tell
end tell


About this entry