You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Terminal Turn Hardware Keys On And Off

I'm trying to script turning on and off the hardware keys on my MacBook that control the volume and brightness. I have a game which I like to assign the function keys to certain controls and going into System Preferences every time I want to play is a hassle.

If someone could tell me how to do this using the +defaults write+ command that would be most appreciated.

The preference is located in: +System Preferences > Keyboard & Mouse > Keyboard > Use all F1, F2, etc. keys as standard function keys+ and it is just a simple check box.

13in. MacBook 2GHz Core 2 Duo 2GB RAM, Mac OS X (10.5.2)

Posted on Feb 23, 2008 2:39 PM

Reply
Question marked as Top-ranking reply

Posted on Feb 24, 2008 10:33 AM

Matt

You can do this with
defaults write -g com.apple.keyboard.fnState true

Undoing it should be obvious 😉
3 replies

Feb 24, 2008 5:40 PM in response to Michael Conniff

Thanks Michael, that got me in the right direction but it didn't work.

Before I wrote to com.apple.keyboard.fnState I read from it to see what was there.

defaults read -g com.apple.keyboard.fnState


When the checkbox was on in System Preferences (acted like function keys) the above resulted in 1. When the checkbox was off (hardware keys) it resulted in 0.

When I ran +defaults write -g com.apple.keyboard.fnState true+ it didn't make the keys only work as function keys, in fact it didn't change anything. If I wrote a true or a false the keys didn't change from whatever they were set to before I ran that command.

When I read back com.apple.keyboard.fnState whatever I had written to before was there. Writing false to that preference resulted in false being returned and the key type never changing.

If I wrote a 1 or a 0 it didn't change how the keys behaved yet checking or unchecking the System Preferences checkbox (resulting in a 1 or 0 being read from the preference) would change the behavior of the keys.

I even restarted (effectively killing all processes). That resulted in the sum total of nothing. I'm really stumped on this one. Googling "fnstate" resulted in a handful of of cases just like this that I hadn't discovered in my previous Googlings. None of them with a solution that worked for me.

Is there some silly mistake that I'm making here or what?

Feb 25, 2008 12:56 PM in response to Matt Skorina

Matt

I did not have this property in my plist initially, so I backed up the file and changed it in the GUI. I then discovered this entry in "~/Library/Preferences/.GlobalPreferences.plist":
<key>com.apple.keyboard.fnState</key>
<false/>

But defaults read -g com.apple.keyboard.fnState will return this as '0', or '1' if the value is <true/>.

However, the command I posted omitted an important flag, to prevent whatever is input being treated as a string 😟 So try:
defaults write -g com.apple.keyboard.fnState -boolean true

Now the read command will display '1', but in the file the value will be '<true/>'.

Sorry I missed that out before!

Terminal Turn Hardware Keys On And Off

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.