Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know you can toggle this option on and off in the System Preferences screen for 'keyboard' but I'd like to know if I can do it via a shortcut as I do it all the time.

share|improve this question
up vote 7 down vote accepted

To make the following work, you need to Enable access for assistive devices in System Preferences » Universal Access.

Open Automator, select Service and choose that the service receives no input (near the top).

Double-click Run AppleScript in the Utilities category of the library. Replace the default code snippet of the newly created action with the following:

tell application "System Preferences"
    set current pane to pane id ""
    tell application "System Events"
        tell process "System Preferences"
            click checkbox "Use all F1, F2, etc. keys as standard function keys" of tab group 1 of window "Keyboard"
        end tell
    end tell
end tell

System Preferences will launch, but it will not be displayed and will quit immediately after toggling the setting.

Press Command-S to save, give it the name e.g. Toggle Fn. Result:

enter image description here

Go to System Preferences » Keyboard » Keyboard Shortcuts » Services to assign a keyboard shortcut for this Service.

share|improve this answer
If System Preferences is already running when you perform this command, it will quit. The code to prevent this would have bloated this answer. – Daniel Beck Feb 9 '11 at 18:39
The question is tagged osx-snow-leopard, which this answer seems to require. I don't think I can make a service in OS X 10.5 judging from what I can see in front of me compared to… – Philip Durbin Feb 14 '11 at 1:53
@Philip I don't recall how Services worked in 10.5, but an Automator-created service is just an Automator workflow saved to ~/Library/Services. Maybe you can replicate this manually? To configure the Services menu, use ServiceScrubber. – Daniel Beck Feb 14 '11 at 7:16
this works on 10.6 but for some reason my keyboard shortcut kept failing or firing when I didn't want it to. so i switched to calling it from the command line with osascript based on… – Philip Durbin May 11 '11 at 13:48
@Philip You can always enable the AppleScript menu and store the code as scpt file in ~/Library/Scripts and call from the menu bar. Using the 3rd party FastScripts, you can assign a keyboard shortcut. – Daniel Beck May 11 '11 at 21:06

I know this post is old but on couldn't get the above to run on Mountinan Lion. I found a similar snippet but removed some unnecessary parts.

tell application "System Preferences"
    set current pane to pane ""
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 "Keyboard" of tab group 1 of window "Keyboard"
            click checkbox "Use all F1, F2, etc. keys as standard function keys" of tab group 1 of window "Keyboard"
        end tell
        tell application "System Preferences" to quit
        -- GUI scripting not enabled.  Display an alert
        tell application "System Preferences"
            set current pane to pane ""
            display dialog "UI element scripting is not enabled. Please activate \"Enable access for assistive devices\""
        end tell
    end if
end tell

Hope this helps

share|improve this answer

You could also use a private.xml like this with KeyRemap4MacBook:

<?xml version="1.0"?>
    <autogen>__KeyToKey__ KeyCode::F1, VK_COMMAND | ModifierFlag::NONE, KeyCode::VK_CONFIG_TOGGLE_fn</autogen>
    <autogen>__KeyToKey__ KeyCode::BRIGHTNESS_DOWN, VK_COMMAND | ModifierFlag::NONE, KeyCode::VK_CONFIG_TOGGLE_fn</autogen>
    <identifier vk_config="true">fn</identifier>
    <autogen>__KeyToKey__ KeyCode::BRIGHTNESS_DOWN, KeyCode::F1</autogen>
    <autogen>__KeyToKey__ KeyCode::BRIGHTNESS_UP, KeyCode::F2</autogen>
    <autogen>__KeyToKey__ KeyCode::EXPOSE_ALL, KeyCode::F3</autogen>
    <autogen>__KeyToKey__ KeyCode::LAUNCHPAD, KeyCode::F4</autogen>
    <autogen>__ConsumerToKey__ ConsumerKeyCode::KEYBOARDLIGHT_LOW, KeyCode::F5</autogen>
    <autogen>__ConsumerToKey__ ConsumerKeyCode::KEYBOARDLIGHT_HIGH, KeyCode::F6</autogen>
    <autogen>__ConsumerToKey__ ConsumerKeyCode::MUSIC_PREV, KeyCode::F7</autogen>
    <autogen>__ConsumerToKey__ ConsumerKeyCode::MUSIC_PLAY, KeyCode::F8</autogen>
    <autogen>__ConsumerToKey__ ConsumerKeyCode::MUSIC_NEXT, KeyCode::F9</autogen>
    <autogen>__ConsumerToKey__ ConsumerKeyCode::VOLUME_MUTE, KeyCode::F10</autogen>
    <autogen>__ConsumerToKey__ ConsumerKeyCode::VOLUME_DOWN, KeyCode::F11</autogen>
    <autogen>__ConsumerToKey__ ConsumerKeyCode::VOLUME_UP, KeyCode::F12</autogen>
    <autogen>__KeyToKey__ KeyCode::F1, KeyCode::BRIGHTNESS_DOWN</autogen>
    <autogen>__KeyToKey__ KeyCode::F2, KeyCode::BRIGHTNESS_UP</autogen>
    <autogen>__KeyToKey__ KeyCode::F3, KeyCode::EXPOSE_ALL</autogen>
    <autogen>__KeyToKey__ KeyCode::F4, KeyCode::LAUNCHPAD</autogen>
    <autogen>__ConsumerToKey__ KeyCode::F5, ConsumerKeyCode::KEYBOARDLIGHT_LOW</autogen>
    <autogen>__ConsumerToKey__ KeyCode::F6, ConsumerKeyCode::KEYBOARDLIGHT_HIGH</autogen>
    <autogen>__ConsumerToKey__ KeyCode::F7, ConsumerKeyCode::MUSIC_PREV</autogen>
    <autogen>__ConsumerToKey__ KeyCode::F8, ConsumerKeyCode::MUSIC_PLAY</autogen>
    <autogen>__ConsumerToKey__ KeyCode::F9, ConsumerKeyCode::MUSIC_NEXT</autogen>
    <autogen>__ConsumerToKey__ KeyCode::F10, ConsumerKeyCode::VOLUME_MUTE</autogen>
    <autogen>__ConsumerToKey__ KeyCode::F11, ConsumerKeyCode::VOLUME_DOWN</autogen>
    <autogen>__ConsumerToKey__ KeyCode::F12, ConsumerKeyCode::VOLUME_UP</autogen>

See the source for the key code values and predefined settings.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .