Skip to content

Instantly share code, notes, and snippets.

@karanjitsingh
Created December 27, 2021 01:33
Show Gist options
  • Save karanjitsingh/254051ead27786502dc54a29d3f68b70 to your computer and use it in GitHub Desktop.
Save karanjitsingh/254051ead27786502dc54a29d3f68b70 to your computer and use it in GitHub Desktop.
AppleScript to toggle fn key
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 application process "System Preferences"
repeat until exists tab group 1 of window "Keyboard"
delay 0.5
end repeat
click radio button "Keyboard" of tab group 1 of window "Keyboard"
click checkbox "Use F1, F2, etc. keys as standard function keys" of tab group 1 of window "Keyboard"
end tell
tell application "System Preferences" to quit
else
-- GUI scripting not enabled. Display an alert
tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.security"
display dialog "UI element scripting is not enabled. Please activate this app under Privacy -> Accessibility so it can access the settings it needs."
end tell
end if
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment