I can't seem to figure out how to select the correct buttons with Applescript. I am starting to learn vim and want to be able to toggle the Caps Lock Key between Caps Lock and Ctrl. I have marked the steps which I need to complete.
I found (this post) but it seems to be a little hacky. Maybe it's the way it supposed to be but it shows the system pref. window every time I use it, unlike (this code) that toggles the fn key and works seemlessly.
Could anyone offer some advice?
Here's my code:
tell application "System Events"
tell application "System Preferences"
reveal anchor "keyboardTab" of pane "com.apple.preference.keyboard"
end tell
-- [STEP 1] set mod_keys to value of output from within "Modifier Keys..."
set mod_keys to button "Modifier Keys..." of tab group 1 of window 1 of application process "System Preferences"
-- I would prefer not to have to click the mod_keys because I don't want the window popping up but if it's necessary then okay
click mod_keys
-- [STEP 2] set cl_key to the second dropdown of mod_keys
set cl_key to menu item 2 of menu 1 of pop up button 4
set cl to value of cl_key
if cl is menu item 2
set q to menu item 2 of menu 1 of pop up button 4
else
set q to menu item 1 of menu 1 of pop up button 4
end if
end tell
-- This is just to make sure it works, but may be unneccessary
if application "System Preferences" is running then
tell application "System Preferences" to quit
end if
return q
Here is the Modifier Keys Screenshot:
enter link description here http://imageshack.us/a/img833/474/o5co.png