Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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

share|improve this question
add comment

3 Answers

up vote 3 down vote accepted
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, but I don't know any way to apply the changes without logging out and back in.

share|improve this answer
    
Exactly what I was looking for, thanks. –  jkbr Aug 12 '12 at 15:08
2  
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 –  jkbr Feb 21 '13 at 19:06
    
@jkbr Your app on github is just the sort of thing I was searching for. Thanks! –  mdwhatcott Sep 14 '13 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. –  Lauri Ranta Sep 14 '13 at 17:51
1  
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 at 15:28
show 1 more comment

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

share|improve this answer
    
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. –  Nathan Greenstein Aug 12 '12 at 15:48
add comment

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

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:

https://github.com/nelsonjchen/fntoggle

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.