Last active
July 4, 2016 05:07
-
-
Save alampros/2b81af6cfc564f6accd3 to your computer and use it in GitHub Desktop.
AppleScript to toggle "Use all F1, F2, etc. keys as standard function keys" in System Preferences > Keyboard.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--Originally posted by "kiodane" at http://forums.macrumors.com/showthread.php?t=383969 | |
tell application "System Preferences" | |
set current pane to pane "com.apple.preference.keyboard" | |
end tell | |
tell application "System Events" | |
if UI elements enabled then | |
tell tab group 1 of window "Keyboard" of process "System Preferences" | |
click checkbox "Use all F1, F2, etc. keys as standard function keys" | |
if (do shell script "defaults read -g com.apple.keyboard.fnState") = "1" then | |
set fnStateRead to "Function Keys - F1, F2, F3..." | |
set fnStateMessageRead to "F keys are now real function keys." | |
else | |
set fnStateRead to "Special Keys - Volume, iTunes..." | |
set fnStateMessageRead to "F keys are now special media keys." | |
end if | |
do shell script "/usr/local/bin/terminal-notifier -message \"" & fnStateMessageRead & "\" -title \"" & fnStateRead & "\" -activate com.orderedbytes.ControllerMate4" | |
end tell | |
tell application "System Preferences" | |
quit | |
end tell | |
else | |
tell application "System Preferences" | |
set current pane ¬ | |
to pane "com.apple.preference.security" | |
display dialog ¬ | |
"Accessibility control is not enabled. Under Privacy => Accessibility, check the box next to the name of this application." | |
end tell | |
end if | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there a reason you prefer to use terminal-notifier over
display notification
? And isn't it easier to check the value of the checkbox, rather than reading the defaults?it could simplify and make the script more readable, by maybe doing something along the lines of:
I'd like to hear your thoughts on this, I'm very new to AppleScript :)
Edit:
I just found out by messing around a bit you can actually open the correct tab and select Accessibility by doing: