Posted on 12-28-2022 07:27 AM
Im trying to create a self-service policy with a script that will disable the "smart quotes" system setting but am running into issues getting this to work.
defaults write NSGlobalDomain NSAutomaticQuoteSubstitutionEnabled -bool false
Above command seems to work fine when using it on my local device but when trying to use this command in a jamf policy, no luck. any ideas on how I can get this to work? Thanks in advance.
Solved! Go to Solution.
Posted on 12-30-2022 02:26 PM
So as @AJPinto has pointed out the Jamf binary will execute everything as root but Jamf also knows who the current user is and stores that in the variable $2 at runtime so you could try something like the following to run it as the current user:
su $2 -c "defaults write NSGlobalDomain NSAutomaticQuoteSubstitutionEnabled -bool false"
Alternatively you could get the current user yourself via another command and then use those 2 commands in the files and processes payload of a policy:
currentUser=$(stat -f "%Su" /dev/console); su $currentUser -c "defaults write NSGlobalDomain NSAutomaticQuoteSubstitutionEnabled -bool false"
Hope that helps.
Posted on 12-28-2022 07:55 AM
How are you trying to deploy it? If it works when you run it manually, but not when you run it with JAMF I am going to wager its something that needs to be done in the user space and not root space. Keep in mind everything JAMF does is done as root.
Posted on 12-28-2022 08:18 AM
Thanks for the reply, Iv been deploying it as a "File and process > Execute Command". Ill give it a try using the user space.
Posted on 12-29-2022 05:12 AM
Yep, that runs the command as root. If it is something that needs to be done in the user space, you are setting the value for the root user.
Posted on 12-30-2022 02:26 PM
So as @AJPinto has pointed out the Jamf binary will execute everything as root but Jamf also knows who the current user is and stores that in the variable $2 at runtime so you could try something like the following to run it as the current user:
su $2 -c "defaults write NSGlobalDomain NSAutomaticQuoteSubstitutionEnabled -bool false"
Alternatively you could get the current user yourself via another command and then use those 2 commands in the files and processes payload of a policy:
currentUser=$(stat -f "%Su" /dev/console); su $currentUser -c "defaults write NSGlobalDomain NSAutomaticQuoteSubstitutionEnabled -bool false"
Hope that helps.
Posted on 01-03-2023 07:14 AM
Thanks for the info r0blee, this is very helpful.