Keyboard Modifier toggle from command to …
Imported from the Apple Support Forums via the Wayback Machine 🔗
Hi guys I have this script working after a bit of tweaking and the script was originally posted by Lance Ball long ago for Tiger and was for users with a Pc Keyboard. I am swapping control and command for pure gaming preferences; Unfortunately, The script will not work when the Keyboard Shortcuts menu has been opened last in system preferences, would anyone know how to slightly tweak this applescript so that it selects the keyboard button prior?
--
********************************************************************************
-- Utility script to switch keyboard mapping for Command and Control keys.
-- Author: Lance Ball & tweaked by Beau Parkes for Snow Leopard
--
********************************************************************************
-- Open System Preferences
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
-- Open up the Modifier Keys sheet
click button "Modifier Keys…" of tab group 1 of window "Keyboard"
tell sheet 1 of window "Keyboard"
-- get the text of the 3rd pop up button
click pop up button 5
click menu item "Apple Internal Keyboard / Trackpad" of menu 1 of pop up button 5
set commandKey to value of pop up button 3
-- looks like we're in default mode. Swap the keys
if commandKey ends with "Control" then
click pop up button 3
click menu item 4 of menu 1 of pop up button 3
click pop up button 1
click menu item 2 of menu 1 of pop up button 1
else
-- We're in PC keyboard mode. Swap back to the defaults
click button "Restore Defaults"
end if
-- close the sheet
click button "OK"
end tell
end tell
tell application "System Preferences" to quit
else
-- UI elements 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.
Check "Enable access for assistive devices""
end tell
end if
end tell
********************************************************************************
Thanks guys, Im excited to hear how I can improve the code.
Beau Parkes
4 replies
Sign in or join Beachball Help to reply.
- 0
- 0
- 0
- 0