defaults write not working through jamf

vanschip-gerard
Contributor

I have several little scripts that writes to default files for various things. In order to make sure it writes to the users defaults I use loggedInUser to pull the logged in user.

All this works 100% through the terminal but when I run it via a script actions via self service it does not seem to work. The policy shows no fail but the change does not take place.

Thought at first that it was loggedInUser but that works. This script used to work on Jamf Pro 27, something changed?

#!/bin/bash

loggedInUser=$(stat -f%Su /dev/console)

/usr/bin/defaults write /Users/$loggedInUser/Library/Preferences/com.apple.screencapture.plist type jpg

## Make sure the plist we just wrote to as root is owned by the user and not root
/usr/sbin/chown $loggedInUser /Users/$loggedInUser/Library/Preferences/com.apple.screencapture.plist

killall SystemUIServer
1 REPLY 1

skeenan07
New Contributor III

I'm not sure if something has changed, but I would try something like the following:

sudo -u "$loggedInUser" /usr/bin/defaults write /Users/$loggedInUser/Library/Preferences/com.apple.screencapture.plist type jpg

This way, you are writing to the plist as the user, so you shouldn't need to adjust the permissions.