Apple - Toggle "Use all F1, F2 as standard keys" via script

tell application "System Preferences"
    reveal anchor "keyboardTab" of pane "com.apple.preference.keyboard"
end tell
tell application "System Events" to tell process "System Preferences"
    click checkbox 1 of tab group 1 of window 1
end tell
quit application "System Preferences"

You could also use defaults write -g com.apple.keyboard.fnState -bool true, but I don't know any way to apply the changes without logging out and back in again.


I don't know about script but with some handy reverse-engineering and Googling, I made this since I didn't like the existing AppleScript GUI stuff that was out there:

https://github.com/nelsonjchen/fntoggle

Compiled binary (Toss into your PATH or if you don't know what that is then /usr/local/bin/): https://github.com/nelsonjchen/fntoggle/releases

Call it from anything (ControlPlane, Automator, sh, etc) by running fntoggle on or fntoggle off.

This script does not require GUI accessibility to be turned on. It also does not require logging out and back in.


You can read the current state with the following. (1 for F-keys, 0 for media/brightness etc)

defaults read "Apple Global Domain" "com.apple.keyboard.fnState"

You can write it, however it won't change until you reboot. (I tried killing Dock and Finder instead, no luck)

defaults write "Apple Global Domain" "com.apple.keyboard.fnState" "1" ## F1 F2 etc
defaults write "Apple Global Domain" "com.apple.keyboard.fnState" "0" ## Brightness/Media

I suspect somebody with more knowledge on what reads this plist file could write up a script to kill and restart whatever reads this plist, which should make it acknowledge the change.