Skip to content

Instantly share code, notes, and snippets.

@lamdor
Created July 21, 2009 22:58
Show Gist options
  • Select an option

  • Save lamdor/151694 to your computer and use it in GitHub Desktop.

Select an option

Save lamdor/151694 to your computer and use it in GitHub Desktop.
tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.keyboard"
end tell
tell application "System Events"
-- If we don't have UI Elements enabled, then nothing is really going to work.
if UI elements enabled then
tell application process "System Preferences"
get properties
click button "Modifier Keys…" of tab group 1 of window "Keyboard & Mouse"
tell sheet 1 of window "Keyboard & Mouse"
-- get the text of the 3rd pop up button
set commandKey to value of pop up button 1
if commandKey ends with "Command" then
-- switch command to be option
-- switch option to be command
click pop up button 1
click menu item 3 of menu 1 of pop up button 1
delay 0.1
click pop up button 2
click menu item 4 of menu 1 of pop up button 2
delay 0.1
else
-- switch command to be command
-- switch option to be option
click pop up button 1
click menu item 4 of menu 1 of pop up button 1
delay 0.1
click pop up button 2
click menu item 3 of menu 1 of pop up button 2
delay 0.1
end if
click button "OK"
end tell
end tell
tell application "System Preferences" to quit
else
-- GUI scripting not enabled. Display an alert
tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.universalaccess"
display dialog "UI element scripting is not enabled. Please activate \"Enable access for assistive devices\""
end tell
end if
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment