Jump to content

Toggle Fn keys as standard keys


Recommended Posts

  • 4 years later...
  • 5 weeks later...

You can use custom script like:

 

state=$(defaults read "Apple Global Domain" "com.apple.keyboard.fnState")

if ((state)); then
  echo "true"
  defaults write "Apple Global Domain" "com.apple.keyboard.fnState" "0" ## Brightness/Media
else
  echo "false"
  defaults write "Apple Global Domain" "com.apple.keyboard.fnState" "1" ## F1 F2 etc
fi

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

 

Link to comment
  • 3 weeks later...
  • 3 weeks later...

This is still a work in progress but I think it should work with os Catalina and Big Sur

on alfred_script(q)
set theCheckboxBoolean to false
set checkboxcompare to "Use F1, F2, etc."
set i to 0

tell application "System Preferences"
	reveal anchor "keyboardTab" of pane "com.apple.preference.keyboard"
end tell
tell application "System Events"
	tell process "System Preferences"
		tell window "Keyboard"
			set listCheckboxes to (entire contents as list)
			repeat with thisItem in listCheckboxes
				if class of thisItem is checkbox then
					set checkboxtitle to title of thisItem as text
					if checkboxtitle contains checkboxcompare then
						set theCheckbox to thisItem
						tell theCheckbox
							click theCheckbox
							log (its value as boolean)
							set theCheckboxBoolean to (its value as boolean)
						end tell
						exit repeat
					end if
				end if
				set i to i + 1
				delay 0.04
			end repeat
		end tell
	end tell
end tell

quit application "System Preferences"
return theCheckboxBoolean
end alfred_script

 

Link to comment
  • 2 months later...

For anyone else trying to make this work - I've finally gotten my solution to work.

 

The code is based here:

https://github.com/MrSimonC/Toggle-Mac-Function-Keys

 

but for brevity, here is the contents of the apple script file:

 

-- Apple Script (i.e. Use in Apple's Script Editor Application) to Toggle Function Keys / Media keys on/off
-- Tested on MacOS Big Sur (11.4) June 2021
-- Project Path: https://github.com/MrSimonC/Toggle-Mac-Function-Keys

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

 

Hope someone finds it useful!

Simon.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...