Create a gist now

Instantly share code, notes, and snippets.

Activate and Deactivate function keys using AppleScript.

Location Aware Functional Keys

  • Put both scripts in Automator apps
  • Set ControlPlane to start (and hide) both apps
  • Grant Accessibility permissions to Automator
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"
set theCheckbox to checkbox "Use all F1, F2, etc. keys as standard function keys"
tell theCheckbox
if not (its value as boolean) then click theCheckbox
end tell
end tell
else
tell application "System Preferences"
set current pane ¬
to pane "com.apple.preference.universalaccess"
display dialog ¬
"UI element scripting is not enabled. Check \"Enable access for assistive devices\""
end tell
end if
end tell
tell application "System Preferences"
quit
end tell
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"
set theCheckbox to checkbox "Use all F1, F2, etc. keys as standard function keys"
tell theCheckbox
if (its value as boolean) then click theCheckbox
end tell
end tell
else
tell application "System Preferences"
set current pane ¬
to pane "com.apple.preference.universalaccess"
display dialog ¬
"UI element scripting is not enabled. Check \"Enable access for assistive devices\""
end tell
end if
end tell
tell application "System Preferences"
quit
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment