Script to Enable/Disable "Smart Quotes"

SuperGrover
New Contributor II

Hey folks, 

Im trying to create a Self-Service policy that will Disable or Enable the "Smart Quotes" keyboard feature in system preferences. When I run this code in my Coderunner app it works perfectly, but as soon as I load the script in the into a Self-Service policy I seem to have issues. The policies behavior looks good, popup comes up but the setting does not change. Any ideas? Thanks in advance

 

 

 

#!/bin/bash

#Grab current logged in user
user=`ls -la /dev/console | cut -d " " -f 4`

#Check smartquote status
currentstatus=$(defaults read NSGlobalDomain NSAutomaticQuoteSubstitutionEnabled)

#SwiftDialog Location
dialog="/usr/local/bin/dialog"

#DISABLES
if [ $currentstatus = 1 ]; then
	$dialog --message "You are about to disable Smart Quotes" --icon "/usr/local/images/deepwatch-Logo.png" --mini --button1text "Disable" --button2text "Cancel"
	sudo -u $user defaults write NSGlobalDomain NSAutomaticQuoteSubstitutionEnabled -bool false
	sudo killall Finder
fi

#ENABLES
if [ $currentstatus = 0 ]; then
	$dialog --message "You are about to Enable Smart Quotes" --icon "/usr/local/images/deepwatch-Logo.png" --mini --button1text "Enable" --button2text "Cancel"
	sudo -u $user defaults write NSGlobalDomain NSAutomaticQuoteSubstitutionEnabled -bool true
	sudo killall Finder
fi

echo $currentstatus

exit 0

 

 

 

1 ACCEPTED SOLUTION

sdagley
Esteemed Contributor II

@SuperGrover A few suggestions:

To run a command as another https://scriptingosx.com/2020/08/running-a-command-as-another-user/ is a more reliable mechanism that extracting the user from /etc/console

You don't need a sudo for the killall Finder command because when Jamf is running the script it should be running as root

Killing the Finder doesn't force a prefs reload, that would be the cfprefsd process

View solution in original post

3 REPLIES 3

sdagley
Esteemed Contributor II

@SuperGrover A few suggestions:

To run a command as another https://scriptingosx.com/2020/08/running-a-command-as-another-user/ is a more reliable mechanism that extracting the user from /etc/console

You don't need a sudo for the killall Finder command because when Jamf is running the script it should be running as root

Killing the Finder doesn't force a prefs reload, that would be the cfprefsd process

SuperGrover
New Contributor II

Thanks for the reply @sdagley

So your suggesting I use  

currentUser=$( echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ { print $3 }' )

with a cfprefsd instead of a "killall Finder"? 

SuperGrover
New Contributor II

That did the trick, really appreciate it @sdagley