How to Quickly Toggle your Keyboard’s Function Keys

by Tom on January 30, 2009

If you have a MacBook, MacBook Pro or are using Apple’s Aluminum Keyboard, you can control some commonly used functions, such as iTunes playback, volume, Dashboard etc., directly with the function keys at the top of the keyboard. These keys actually have dual functionality: either they control the functions mentioned above, or they act as ordinary function keys (F1-F19) and trigger whatever action the current application has mapped to them.

They way you switch between these two modes is by using the fn key on your keyboard. By pressing and holding the fn key and then pressing a function key, you trigger the alternate function. Which function is the default function and which is the alternate function triggered by the fn key, is set in System Preferences->Keyboard & Mouse (see the screenshot).

Sometimes it would be handy to be able to switch the function keys mode without the need to launch System Preferences. If you happen to run Windows® in VMWare Fusion or Parallels, you might have noticed that many apps in Windows make use of the F-keys. Mac applications usually offer shortcuts based on pressing a letter or a number together with one or more modifier keys. On Windows the use of the keys F1-F20 is more common.

The problem is that when your Mac’s function keys are set to trigger the special functions instead of the F-keys by default, you have to press the fn key together with the appropriate function key. And if some command in a Windows application is triggered by Ctrl+F3, you’d need to press fn+Ctrl+F3. Due to the location of the fn-key, this can be quite difficult.

That said, a quick way to toggle the function key functionality would be handy. After searching around for a bit, I found a pretty easy way to achieve this via AppleScript.

What this AppleScript does is simply launch System Preferences and toggle the appropriate checkbox. It’s not instant, since System Preferences actually has to be launched and quit when the checkbox has been toggled. But it’s definitely more comfortable running this script from the script menu than doing it all by hand.

If you want to give this script a try, here’s what you need to do:

  • Make sure you are using Mac OS X Leopard. The script wasn’t tested on Tiger or older and I don’t know if it would work.
  • Download the AppleScript.
  • Copy the script to [your user folder]/Library/Scripts.
  • Launch AppleScript Utility from the Applications/AppleScript folder.
  • In AppleScript Utility, activate the checkboxes Enable GUI Scripting and Show Script menu in menu bar.

That’s it. Now, whenever you need to quickly switch between the two modes of your keyboard’s function keys, simply select the script Toggle Function Keys from the system-wide script menu.

For even more convenience, check out Red Sweater Software’s FastScripts. It lets you assign keyboard shortcuts to scripts in your AppleScript menu.

This script is based on a post at fall-line.com.
Email This Post Email This Post  | PrintPrint/Save as PDF | Share: 
  • del.icio.us
  • Facebook
  • Google
  • Furl
  • Reddit
  • StumbleUpon
  • Technorati
  • TwitThis

{ 4 comments… read them below or add one }

Patte 03.05.09 at 11:59 am  

I’ve been looking for a script like this, but… the script comes up with an error:

Translation:


„System Events“ has received an error: „window “Keyboard & Mouse” of application process “System Preferences”“ can’t be read.

Tom 03.05.09 at 12:26 pm  

I’m not that familiar with AppleScript, but it’s quite possible that the script only works when Mac OS is set to English interface language because it accesses elements of System Preferences by name and those names vary in each language.

Maybe this little tool is an alternative for toggling the function keys:
http://kevingessner.com/frog/projects/functionflip/

Patte 03.05.09 at 12:29 pm  

I’ve rewritten it to fit the german language… the first few times it didn’t work,
the I had a closer look and discovered that Apple made a typo when doing the translation:
the wrote the same word twice… whatever. Here’s the working script for the german set as
system language:


tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.keyboard"
end tell

tell application "System Events"
-- If we don't have UI Elements enabled, then nothing is really going to work.
if UI elements enabled then
tell application process "System Preferences"
get properties

click radio button "Tastatur" of tab group 1 of window "Tastatur & Maus"
click checkbox "Die Tasten F1, F2 usw. als als Standard-Funktionstasten verwenden" of tab group 1 of window "Tastatur & Maus"
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.universalaccess"
display dialog "UI element scripting is not enabled. Please activate \"Enable access for assistive devices\""
end tell
end if
end tell

Cheers,
Patte

Matt Gallagher 11.27.09 at 3:33 am  

In Snow Leopard, the two instances of “Keyboard & Mouse” need to be replaced with “Keyboard”.

For people trying to get the program to work on non-English systems, the following strings in the script…

– “Keyboard” (once prior to Snow Leopard, 3 times in Snow Leopard)
– “Keyboard & Mouse” (twice prior to Snow Leopard, never in Snow Leopard)
– “Use all F1, F2, etc. keys as standard function keys” (once)

will need to be changed to the appropriate labels in your user interface. Application names do not need tobe translated, nor do the bundle identifiers (like com.apple.preference.universalaccess).

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


Comments links could be nofollow free.