useful applescript

9 01 2009

I’ve been hooking up my MacBook to the setup (mouse/keyboard/lcd) usually connected to a Windows machine over the last few days.  It works great except for the reversed Command + Option on the keyboard mappings.  I googled for something eloquent and found this; http://randomfoo.net/blog/id/4092.  Unfortunately whenever he did that it is outdated now.  I updated it for Leopard, and I can now just use Spotlight to execute "Change Keyboard" as I saved it as an Application to my Applications folder with that name.  Here is the updated version;

 

tell application "System Preferences"
    activate
    set current pane to pane "com.apple.preference.keyboard"
end tell

tell application "System Events"
    get properties
    tell application process "System Preferences"
        click button "Modifier Keys…" of tab group 1 of window "Keyboard & Mouse"
       
        set commandKey to value of pop up button 1 of sheet 1 of window "Keyboard & Mouse"
       
        — DEBUG
        — display dialog commandKey
       
        –  Default, lets flip
        if commandKey ends with "Command" then
            — click the pop up button menu "Option", this menu does not exist until it is clicked in the GUI
            click pop up button 2 of sheet 1 of window "Keyboard & Mouse"
            — click "Command" of the pop up menu
            click menu item 4 of menu 1 of pop up button 2 of sheet 1 of window "Keyboard & Mouse"
           
            — delay briefly
            delay 1
           
            — click the pop up button menu "Command", this menu does not exist until it is clicked in the GUI
            click pop up button 1 of sheet 1 of window "Keyboard & Mouse"
            — click "Option" of the pop up menu
            click menu item 3 of menu 1 of pop up button 1 of sheet 1 of window "Keyboard & Mouse"
           
            — delay again
            delay 1
           
            — Not Default, lets flip it back
        else
            click button "Restore Defaults" of sheet 1 of window "Keyboard & Mouse"
        end if
       
        — click "OK" to dismiss the sheet
        click button "OK" of sheet 1 of window "Keyboard & Mouse"
       
    end tell
end tell

tell application "System Preferences" to quit


Actions

Information

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




Follow

Get every new post delivered to your Inbox.

%d bloggers like this: