Skip to content

Instantly share code, notes, and snippets.

@enplotz
Created March 24, 2014 19:36
Show Gist options
  • Save enplotz/9747447 to your computer and use it in GitHub Desktop.
Save enplotz/9747447 to your computer and use it in GitHub Desktop.
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