Automate Toggling Function Keys in macOS

April 4, 2021

This one is not a coding problem but a productivity tip. I mostly use JetBrain IDEs for programming on macOS. I need frequent access to function keys (F7, F8, F9, etc.) when I debug some code. Not only those, but also I need access to system function keys very often, to adjust brightness, volume, and to get an overview of open applications, etc.

CLion IDE

In this case, being able to quickly toggle the mode of the function keys would be very useful:

  • Standard function keys (F1, F2, etc.)
  • System function keys (Adjust brightness, volume etc.)

It is possible to do this in System Preferences --> Keyboard, however, it is very slow having to go through these panels.

Keyboard preferences

Using Automator and BetterTouchTool programs we can do much better and faster. In Automator, one can write custom scripts in AppleScript language to control the system. For example, the following snippet toggles a checkbox in the Keyboard Preferences on macOS Big Sur (11.2.2), coincidentally... exactly the one we need.

Check the gist for the full AppleScript.

Next, create a macOS workflow with this script and save it where appropriate.

Automator workflow

Automator --> File --> New --> Worfklow --> Run AppleScript.

Verify that workflow does toggle the function keys by executing the workflow. Next, bind this workflow to a keyboard shortcut using BetterTouchTool.

Better Touch Tool configuration

In my case, instead of a key combination, I chose to bind it to a key sequence: Fn button pressed twice consecutively.

And voilà!

Now, when programming I can switch to standard mode to use keys F7, F8, F9 and when I want to control my computer I can switch back to system function keys.

©2025 oeken. All rights reserved.

Automate Toggling Function Keys in macOS