Toggle Function Keys with Keyboard Maestro

June 08, 2013
Updated on: July 20, 2015 at 16:57

Toggle Function Keys with Keyboard Maestro → via @_patrickwelker

Here’s a little trick how to toggle the function keys on Mac OS X with Keyboard Maestro. I’ve set my F1, F2, etc. keys to perform their standard function not the special features printed on each key. I’m used to holding down the function key to toggle the system sound, brightness and so on, but if you’re in the other camp this macro could be interesting for you.

I have it in my global macros palette which I call up via ^SPACE then I press F to toggle the functions keys and get one of these little growl notification:

growl

UPDATE: I also added a notification center version.

This is how the macro works.

The first step is to read the current function key state with a shell command action and set it to a variable FN_Key_Status.

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

In the next step we use AppleScript to toggle the state of the function keys. It’s as easy as pasting this into an AppleScript action:

tell application "System Preferences"
reveal anchor "keyboardTab" of pane "com.apple.preference.keyboard"
end tell
tell application "System Events" to tell process "System Preferences"
click checkbox 1 of tab group 1 of window 1
end tell
quit application "System Preferences"

The macro now works, but we want it to look good and be informative. I use GrowlNotify to display a Growl notification with a keyboard icon:

(a) if the variable of FN_Key_Status matches a 0 then the special functions keys just switched from on to off, so the following shell script should get triggered:

/usr/local/bin/growlnotify -n FunctionKeys --image /System/Library/PreferencePanes/Keyboard.prefPane/Contents/Resources/Keyboard.icns  -m "OFF: using all F1, F2, etc. keys as standard function keys!"

(b) vice versa, if the variable of FN_Key_Status matches a 1 then trigger this shell script:

/usr/local/bin/growlnotify -n FunctionKeys --image /System/Library/PreferencePanes/Keyboard.prefPane/Contents/Resources/Keyboard.icns  -m "ON: using special features printed on the keys!"

This is what the complete macro looks like:

fn-keys

The cool thing is that you can also use the AppleScript when launching or quitting applications. Let’s say your standard setup is that you use the special function keys, but you want to switch to standard function keys whenever you open an app from the Adobe Suite:

adobe

Then you duplicate the macro and tell it to toggle the keys again if you quit on of the apps.

This is only to give you some ideas. Arguably the better way to do this could be to set a up a If Then Else action in Keyboard Maestro and use to only toggle the function keys if Adobe Photoshop is the front window.

If you don’t want to trouble yourself with using Keyboard Maestro there are apps, like Palua or FNable available in the Mac App Store to rid you of the fun that you would otherwise have if you choose to use Keyboard Maestro for automating this.

DOWNLOAD1

Notification Center Version: DOWNLOAD

If you prefer using LaunchBar click here.

  1. For some people downloading single Keyboard Maestro doesn’t seem to work – they get an error when importing. Try downloading the whole repository as a zip file, this usually works.

comments powered by Disqus

Related Posts