I would like to create a shortcut that toggles the behavior of the function keys between standard function and "special features". Basically it would toggle this setting that is in the macOS system keyboard settings:
How would I do this? Thanks for the help.
defaults write -g com.apple.keyboard.fnState -boolean false
This command doesn't seem to properly take affect. (Although I do see the value change when I read it back).
I don't know how to toggle that programatically.
One thing you could do, is to create a separate preset in BTT, where you record all the F keys and assign media functions to it. Then you activate that preset in BTT using the predefined action "switch to preset".
If that preset is active, BTT would then override the F keys with whatever functions you have assigned. If the preset is inactive you'd have standard F keys.
Ok so I found a solution that seems to be working.
The key is this command:
This reloads the settings after they been written via defaults write.
I added these 2 commands to a shortcut and now I have the functionality I want.
I had trouble getting the previous suggestions to work in Ventura, but here's Apple Script for use in BTT action "Run Apple Script (async in background)" which also solves the original question for a shortcut that toggles the behaviour.
do shell script "if [[ $(defaults read -g 'com.apple.keyboard.fnState') == '0' ]]; then defaults write -g 'com.apple.keyboard.fnState' -boolean true; else defaults write -g 'com.apple.keyboard.fnState' -boolean false; fi; /System/Library/PrivateFrameworks/SystemAdministration.framework/Resources/activateSettings -u;"