Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Script to change keyboard modifer keys?

I'm trying to create a login script to use with Workgroup Manager that will allow me to change the keyboard modifer keys on a client machine. I've done a search and found a few scripts but they don't seem to work. For example the following script:

-------------------------------------------------------------------------------
tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.keyboard"
tell application "System Events"
tell process "System Preferences"
click button "Modifier Keys…" of tab group 1 of window "Keyboard & Mouse"
set curOpt to (get value of pop up button 3 of sheet 1 of window "Keyboard & Mouse")

set curCmd to (get value of pop up button 4 of sheet 1 of window "Keyboard & Mouse")

tell sheet 1 of window "Keyboard & Mouse"
tell pop up button 3
click
click menu item curCmd
end tell
tell pop up button 4
click
click menu item curOpt
end tell
end tell
click button "Ok" of sheet 1 of window "Keyboard & Mouse"
end tell
end tell
quit
end tell
-------------------------------------------------------------------------------

I am trying to get this to work on OS X 10.6 with no luck. Firstly I have seperate options in System Preferences for Keyboard and Mouse settings (the script above points to window "Keyboard & Mouse") and secondly, even after changing the "Keyboard & Mouse" to just "Keyboard" I get an error message about not being about to locate button "Modifier Keys...".

All I'm trying to do is change the Modifier Keys so that Crtl key is set to nothing. Could anyone help me out?

Mac Mini, Mac OS X (10.6.5)

Posted on Mar 24, 2011 4:00 AM

Reply
Question marked as Best reply

Posted on Mar 24, 2011 3:16 PM

This could work... (tested with 10.6.7)... not very fast...
another idea could be a defaults write command, but I am not sure which prefs-file you would have to edit.. maybe .GlobalPreferences.plist...

tell application "System Preferences"

activate

set current pane to pane "com.apple.preference.keyboard"

tell application "System Events"

tell process "System Preferences"

click button 1 of tab group 1 of window 1

set curOpt to (get value of pop up button 3 of sheet 1 of window 1)


set curCmd to (get value of pop up button 4 of sheet 1 of window 1)


click pop up button 4 of sheet 1 of window 1

my setbuttonitem(1)


click pop up button 3 of sheet 1 of window 1

my setbuttonitem(2)


click pop up button 2 of sheet 1 of window 1

my setbuttonitem(3)


click pop up button 1 of sheet 1 of window 1

my setbuttonitem(4)

delay 0.25

keystroke return

end tell

end tell

quit

end tell

on setbuttonitem(valueindex)

tell application "System Events"

tell process "System Preferences"

repeat with i from 1 to 5

key code 126

delay 0.25

end repeat

repeat with i from 1 to valueindex - 1

key code 125

delay 0.25

end repeat

keystroke return

end tell

end tell


end setbuttonitem

16 replies

Script to change keyboard modifer keys?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.