I toggle the "Use all F1, F2 as standard keys" setting very often and would like to automate it via a script (or a keyboard shortcut). Is it possible? I've tried to Google the right arguments for defaults write ... but unsuccessfully.

fn settings

Update: I ended up creating https://github.com/jkbrzt/macos-fn-toggle based of the answers here.

Update II: There's now also — https://github.com/Pyroh/Fluor — a really nice menubar app that allows you to automatically change the behaviour of the keyboard's fn keys depending on the active application.

7 Answers 7

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"

You could also use defaults write -g com.apple.keyboard.fnState -bool true, but I don't know any way to apply the changes without logging out and back in again.

  • 4
    I've packed this script as an app using Automator so that it can be quickly run from Spotlight: github.com/jkbr/macos-fn-toggle Feb 21, 2013 at 19:06
  • @jkbr Your app on github is just the sort of thing I was searching for. Thanks! Sep 14, 2013 at 17:38
  • 1
    You can also save a script as an application from AppleScript Editor. Just paste the script to AppleScript Editor, press ⌘S, and set the format to application.
    – Lri
    Sep 14, 2013 at 17:51
  • As yet another alternative, in automator create a new "service", add the Run Applescript command and paste this in where it says (* Your script goes here *). Save, and then the services menu in all applications will include fn :)
    – Spyder
    Jan 2, 2014 at 22:25
  • 2
    On Mavericks you get an error like: "AppleScript Editor is not allowed assistive access." So you have to go to "Security and Privacy" in the Privacy Tab, select Accesibility and enable your app to do that. You will have to provide admin password to open the lock.
    – user69047
    Jan 30, 2014 at 15:28

I don't know about script but with some handy reverse-engineering and Googling, I made this since I didn't like the existing AppleScript GUI stuff that was out there:


Compiled binary (Toss into your PATH or if you don't know what that is then /usr/local/bin/): https://github.com/nelsonjchen/fntoggle/releases

Call it from anything (ControlPlane, Automator, sh, etc) by running fntoggle on or fntoggle off.

This script does not require GUI accessibility to be turned on. It also does not require logging out and back in.


You can read the current state with the following. (1 for F-keys, 0 for media/brightness etc)

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

You can write it, however it won't change until you reboot. (I tried killing Dock and Finder instead, no luck)

defaults write "Apple Global Domain" "com.apple.keyboard.fnState" "1" ## F1 F2 etc
defaults write "Apple Global Domain" "com.apple.keyboard.fnState" "0" ## Brightness/Media

I suspect somebody with more knowledge on what reads this plist file could write up a script to kill and restart whatever reads this plist, which should make it acknowledge the change.

  • Thanks, that's the correct key. Changing it directly however doesn't seem to change the behaviour. Apr 20, 2014 at 8:01
  • doesn't help although rebooted
    – Daniel
    Apr 21, 2015 at 9:15

Actually, you don`t have to run any app with spotlight or anything, the best way in my opinion is to:

  1. Create new Service in Automator
  2. Drag: "Run Apple script
  3. In the "Service recieves selected": choose no input
  4. Paste this code from this other answer:

    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" 
  5. Save as "yourname"

  6. Open System Preferences → Keyboard → Shortcuts
  7. In the left menu choose: "Services"
  8. In the right, scroll all the way down to the General, and assign your service some unique hotkey, I choose cmd+shift+L

  9. Thats it! It's not very fast or anything, but you don't have to run any app or go to the Preferences yourself.

Addendum: With EL Capitan this works only when Automator is in focus, otherwise (eg. if you invoke the script via a keyboard shortcut) you get "The action “Run AppleScript” encountered an error" message.


Some AppleScript that might help: Applescript to toggle F1-F11 keys as function keys - MacRumors Forums

  • Welcome to Ask Different! You've posted this as an answer, which is only for things that directly answer the question asked. Answers on Ask Different need to be more than just a link. It's okay to include a link, but please summarize or excerpt it in the answer. The idea is to make the answer stand alone. Please take a look at the FAQs for more info. Thanks. Aug 12, 2012 at 15:48

I've written an an app (free) that does just what you're looking for. You can download it directly from http://www.techmasterdesign.com/fnswitch/

The source code is available here: http://www.techmasterdesign.com/forum/viewtopic.php?f=2&t=668

  • Please just note if you want to promote or recommend your own product/blog, there are some guidelines in place for doing so. Following them will help you avoid giving the impression that you're spamming. Could you please edit to explicitly state your affiliation? Thanks.
    – NobodyNada
    May 21, 2020 at 19:49
  • 1
    I'm not sure why the down vote if this is an app that directly addresses the OP's issue. A minor edit of the answer to indicate affiliation would definitely be helpful, but not worth a down vote. +1 for what seems to be a good bit of code and contribution.
    – Allan
    May 21, 2020 at 19:58
  • There’s only one vote on this, so anyone can erase the -1 if they think the answer is clear and useful. @Allan
    – bmike
    Jan 17, 2021 at 17:36
  • it doesnt work on macos sonoma. just shows the preferences and gives 53:65: execution error: System Settings got an error: Can’t set pane id "com.apple.preference.keyboard" to pane id "com.apple.preference.keyboard". (-10006)
    – Nir O.
    Feb 3 at 7:51

Given all the answers I applied the following solution for Yosemite.

Using Automator, I created an app with the following code:

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"

Save it, add it to Applications. To avoid the "AppleScript Editor is not allowed assistive access.", go to System Preferences->Security & Privacy->Privacy tap->Accessibility entry and add your app.

If like me you'd like a shortcut, then in Automator create a new Apple Script with Launch App and select your app. Then go back to System Preferences->Keyboard->Shortcut tabs->Service entry and at the end of the list, assign a shortcut to your script.

You must log in to answer this question.

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