views:

201

answers:

2

I hardly ever use the function keys on my macbook pro. I mostly just use them for volume, brightness, etc. Now that I've started playing Starcraft 2 a bunch, I want to use them without having to press the fn key down.

I want to write a little shell script that will flip the "Use all F1, F2, etc keys as standard function keys" check box. I was thinking I could use the defaults command to change it but I wasn't sure what values to use. This way I don't have to change the the preferences every time I want to play. I can just run the script that'll switch the keys and even launch the game.

Any ideas?

A: 

The command is defaults write -g com.apple.keyboard.fnState, although I've had problems in the past changing it. I ended up just using an AppleScript. Give it a try.

defaults write -g com.apple.keyboard.fnState -boolean true

Edit
To elaborate, the problems I've had is that the actual value is changed, but it doesn't actively change the setting in System Preferences nor does the fnState toggle, because the file is only read at boot/login etc. Also, making changes to a config file that's opened by another task sounds like a good way to corrupt the file.

Robert
+1  A: 

An AppleScript that should do the trick -- taken from http://scriptbuilders.net/files/fn1.1.html, with slight modifications

--Check if GUI Scripting is Enabled
tell application "System Events"
    if not UI elements enabled then
        set UI elements enabled to true
    end if
end tell

--Enable/Disable "Use all F1, F2, etc. keys as standard function keys" option in Keyboard & Mouse Preference pane and close System Preferences
tell application "System Events"
    tell application "System Preferences"
        reveal anchor "keyboardTab" of pane "com.apple.preference.keyboard"
    end tell
    click checkbox 1 of tab group 1 of window 1 of application process "System Preferences"
end tell
if application "System Preferences" is running then
    tell application "System Preferences" to quit
end if

Tested on MacOS 10.6.4

Pumbaa80
This _technically_ isn't a command line solution, since it uses AppleScript to access GUI elements, thus leaving the command line.
David Hollman
if you really want to, you can run this on the command line using `osascript << EOF [paste script here] EOF`
Pumbaa80