Best Way to Toggle "Use F1, F2, Etc Keys as Standard Function Keys"

I have a very simple macro to toggle the "Use F1, F2, etc. keys as standard function keys" setting in the keyboard preferences, because in some apps (e.g. Photoshop) I need the function keys.

image

My problem is that since I finally upgraded to Ventura this doesn't work anymore, since the setting is now hidden much deeper in the settings. I've started to build a more complex macro with various "found image" actions but it seems messy, slow and not very elegant.

Is there a better way of doing this?

The price on this critter is pretty darn steep for what it does...

But if I was toggling the fn setting really often I'd probably pay it for the convenience – at least if I couldn’t' find a similar option for less money.

1 Like

Do you actually need to toggle this? Don't forget that you can flip the keys' behaviour at the time of keypress by holding down the Fn key -- I leave mine set to be standard function keys all the time, then Fn-F10 to mute the sound etc.

If you do need to toggle, here's a macro that uses UI scripting. It's a quick hack so it does depend on "Function Keys" being the eleventh item of the list in the "Keyboard Shortcuts…" sheet. I've left in 1-second delays between each UI operation (the delay 1 lines) which you can change to match your kit's response speed, and used the long-form of nested tells so you can follow along with which part of the UI is being targeted.

Toggle Fn Keys.kmmacros (4.4 KB)

Image

Here is a script I was using for a while to toggle between two touch bar modes. You should be able to modify it for your purposes.

EDIT: Actually, I haven't used it for years actually and just had to adjust it to make it work with the current phrasing on that Pref panel...Sometimes I have to trigger it twice... it should be a good starting point for you at least.

tell application id "com.apple.systempreferences"
	reveal pane id "com.apple.preference.keyboard"
end tell

tell application "System Events"
	tell process "System Preferences"
		set currentState to value of attribute "AXValue" of pop up button 2 of tab group 1 of window "Keyboard"
		if currentState is "Expanded Control Strip" then
			set newState to "App Controls"
			tell pop up button 2 of tab group 1 of window "Keyboard"
				perform action "AXShowMenu"
				tell menu 1
					click menu item newState
				end tell
			end tell
		else if currentState is "App Controls" then
			set newState to "Expanded Control Strip"
			tell pop up button 2 of tab group 1 of window "Keyboard"
				perform action "AXShowMenu"
				tell menu 1
					click menu item newState
				end tell
			end tell
		end if
	end tell
end tell

quit application "System Preferences"

Thank you all! I am not familiar with AppleScript at all and have just hacked together this solution for now:

image

It seems like there just is no super elegant solution.

As @peternlewis said in the other thread, it's an Apple shortcoming. You can, for example, change the Function Key operation "invisibly" with a single shell command -- but the new setting won't take effect until you log out and back in and there's no obvious other way to force a "refresh".

But if you are after another, less intrusive, way of doing this -- KM to the rescue! It'll take a few minutes to set up but:

Make a new Macro Group that is "available in all application except:" and add Photoshop (and any other apps you want to always treat function keys as function keys) to the exception list. Then populate that group with macros triggered by each function key that use the "Simulate the Hardware Key" action with appropriate settings. For example:

Then you'll have the equivalent of "F1 as standard..." turned on in your excepted apps and turned off in all others -- I think you'll lose the "override with the Fn key" option though, unless you build that in yourself by including an "If... Fn key is down" check.

1 Like

Bit of a surprising omission in Maestro - but for what you want, maybe check out the open source "fluor" app, which you can install via brew:

brew install fluor

Fluor allows you to manage the behavior of the keys based on the currently running app (or globally, presumably via a Maestro shortcut).

This looked like an interesting challenge. So I updated the ideas in this thread using the new Button Action features, and added a few new features. It puts an icon in your system menu bar telling you whether the keys are turned on or off. And you can change the setting by pulling down its menu.

I have an ever shorter, quicker way to do this, but it seems to me that people will want to see the Button Action doing its work.

The only small downside to this approach is that it takes 5 to 10 seconds to update the icon in the system menu (for reasons that are tough to explain.) As I said, I have a quicker way to write this code, but this is probably what people want to see.

Fn Key Macro (v11.0.1)

Fn Key.kmmacros (24 KB)

2 Likes

Or simply :

1 Like

You could also set a hotkey to activate this palette for an action, if you want to use it within Photoshop too occasionally

Thanks! When I have some time or when my hacked together solution stops working I'll try this!

I've been using that macro for three weeks now, and it's cool. I don't really change that feature very often, but it has opened my eyes to new methods of using KM and the system menu bar.

1 Like