PDA

View Full Version : AppleScript - Slow Keys




technist
May 18, 2013, 04:46 AM
I would like to create an AppleScript that turns on Slow Keys, and another that turns it off. The reason I would like to do this because: I have a 2.4GHz wireless keyboard that I use "simultaneously" with multiple computers (one of them being a MacBook). I don't use the keyboard on both computers literally at the same time, but switch back-and-forth as I prefer. When I switch from PC to Mac, I just enter Ctrl-Alt-Del and that locks my screen without displaying the password dialog, thus preventing characters I hit on my keyboard from displaying on my PC (in addition to my Mac). But when I "switch" to my PC, when I activate the screensaver on my Mac, the password dialog shows when you press a key and, of course, accepts any characters typed through the keyboard. And anytime I hit "enter" it, of course, displays that I entered my password incorrectly. If I can create an Applescript to activate slow keys (and tie it to a keyboard shortcut), I can prevent characters from being accepted on both computers at the same time. It's not a huge deal, but it would be really nice if I could get it to work.

I'm not really familiar with AppleScript, but here's what I have so far (I'm also not sure whether this would run the script in the background or not):

tell application "System Preferences"
activate
end tell

tell application "System Events"
tell process "System Preferences"
click menu item "Universal Access" of menu "View" of menu bar 1
delay 2
tell window "Universal Access"
tell first tab group
click radio button 3
end tell
end tell
end tell
end tell

This gets me to Universal Access > Keyboard (tab), but I would like it to get to select "Slow Keys: On"/"Slow Keys: Off". Any suggestions?

Thanks for your help!



kryten2
May 18, 2013, 09:58 AM
Try this :

tell application "System Preferences"
activate
end tell

tell application "System Events"
tell process "System Preferences"
click menu item "Universal Access" of menu "View" of menu bar 1
delay 2
tell window "Universal Access"
tell first tab group
click radio button 3
delay 1
-- If Slow Keys are off then turn them on
if value of radio button "Off" of radio group 2 is 1 then
click radio button "On" of radio group 2
else
-- If Slow Keys are on then turn them off
click radio button "Off" of radio group 2
end if
end tell
end tell
end tell
end tell


Note : Tested on Leopard.