Posted on 01-06-2017 04:31 AM
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
Posted on 01-06-2017 10:03 AM
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
Posted on 01-08-2017 12:41 AM
@etippett Defaults is part of the preferences system, so shouldn't need to kill cfprefsd
Posted on 01-09-2017 12:00 AM
What if you wanted this as a global policy? As its in self service I technically wouldn't know the username of the person.....
Posted on 01-09-2017 06:05 AM
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
Posted on 01-09-2017 06:07 AM
@etippett we have a mixed site of local mobile accounts and directory accounts would this cause an issue?
Posted on 01-09-2017 06:15 AM
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?
Posted on 01-09-2017 06:27 AM
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
Posted on 01-09-2017 06:47 AM
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.
Posted on 01-10-2017 02:51 AM
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.
Posted on 01-10-2017 06:29 AM
In that case you'll need to use ls -l /dev/console | awk '{print $3}'
to get the current user.
Posted on 01-11-2017 11:22 AM
Thank you btw!
Posted on 01-31-2017 12:54 PM
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.
Posted on 02-20-2018 03:52 PM
smccullar - Any luck? This is exactly what I need to accomplish (apply the F1 as standard function preference to all users... unknown users)!
Thanks!
Posted on 08-08-2018 09:05 PM
@smccullar did you get this to work?