Skip to main content
Question

Script to Enable "Use F1, F2, etc. keys as standard Function keys on external keyboards"

  • January 6, 2017
  • 14 replies
  • 38 views

Forum|alt.badge.img+5

I have created a self service item for some software called iTerm2 including a DMG that pushes out a configured preference file which includes F key configuration and profiles.

As part of the requirement for this I want to add a script to automatically turn on the above preference in keyboard settings for the user.

Does anyone have anything already created to cover this that doesn't require a restart of the system?

Thanks

Jon

14 replies

Forum|alt.badge.img+10
  • Contributor
  • 175 replies
  • January 6, 2017

I've used this in the past (change path to reflect the name of the user for which you want to change the setting)

defaults write /Users/username/Library/Preferences/.GlobalPreferences com.apple.keyboard.fnState 1
chown username /Users/username/Library/Preferences/.GlobalPreferences

With the caching of preferences with cfprefsd, you will probably need to kill that process in order for this to take effect. Worse, it may actually overwrite your changes. My workflow changes these settings on first boot, so that's not an issue for me.

Eric


bentoms
Forum|alt.badge.img+35
  • Hall of Fame
  • 4331 replies
  • January 8, 2017

@etippett Defaults is part of the preferences system, so shouldn't need to kill cfprefsd


Forum|alt.badge.img+5
  • Author
  • Contributor
  • 25 replies
  • January 9, 2017

What if you wanted this as a global policy? As its in self service I technically wouldn't know the username of the person.....


Forum|alt.badge.img+10
  • Contributor
  • 175 replies
  • January 9, 2017

Ah, that's right, @bentoms . Thanks for calling out my error.

@jonathan.rudge Is the account your users use to login to the OS the same as what they are using for Self Service (directory-based)? If so, just use the built-in $3 variable for user in your script.
[https://www.jamf.com/jamf-nation/articles/146/script-parameters](link URL)

Or, you can get the username of the currently logged in user with this code: ls -l /dev/console | awk '{print $3}'
Store that in a variable, and use that variable in the other commands.

Good luck!
Eric


Forum|alt.badge.img+5
  • Author
  • Contributor
  • 25 replies
  • January 9, 2017

@etippett we have a mixed site of local mobile accounts and directory accounts would this cause an issue?


Forum|alt.badge.img+10
  • Contributor
  • 175 replies
  • January 9, 2017

Mobile accounts are directory accounts. Are the username and password they use to login to the OS the same as what they use to login to Self Service?


Forum|alt.badge.img+5
  • Author
  • Contributor
  • 25 replies
  • January 9, 2017

Sorry I didn't explain myself very well!

We have some users where a mobile account has been created when logging onto the Mac that has sync'd with AD (first name.surname)

New (today world) are created by adding a local account for the user and then they set the account. (this could be an abbreviation of their first name, sometimes with or without the surname i.e. Jon or JonR


Forum|alt.badge.img+10
  • Contributor
  • 175 replies
  • January 9, 2017

You still haven't said how they login to Self Service (perhaps you don't require them to), so it's uncertain whether $3 will work for you. Therefore it sounds like you're best off using the command I provided above to get the currently logged in user.


Forum|alt.badge.img+5
  • Author
  • Contributor
  • 25 replies
  • January 10, 2017

Sorry, they don't logon to self service, we push out the application to the device for them to use without the additional need to sign in.


Forum|alt.badge.img+10
  • Contributor
  • 175 replies
  • January 10, 2017

In that case you'll need to use ls -l /dev/console | awk '{print $3}' to get the current user.


Forum|alt.badge.img+5
  • Author
  • Contributor
  • 25 replies
  • January 11, 2017

Thank you btw!


  • 0 replies
  • January 31, 2017

For our end of year testing, I need to have the Use all F1, F2, etc keys as standard function keys checked for all user accounts(current and future add accounts) on a group of computers. I tried a basic script but it doesn't work because it doesn't run as the logged in user. I see that you are saying to add the variable. The thing is I do not know how/where to add the variable. I'm still able to write only very basic scripts.


Forum|alt.badge.img
  • New Contributor
  • 1 reply
  • February 20, 2018

smccullar - Any luck? This is exactly what I need to accomplish (apply the F1 as standard function preference to all users... unknown users)!
Thanks!


Forum|alt.badge.img+6
  • New Contributor
  • 9 replies
  • August 9, 2018

@smccullar did you get this to work?