Multi monitor script works locally, not through jamf policy

Tjernigan
New Contributor III

I have poured through all the threads and found a script that works locally to change the wallpaper of all monitors on a system if run locally. The script however, does not work when pushed through jamf. I get a successful message but not change in the wallpaper. The script I'm using is:

!/bin/bash

osascript -e 'tell application "System Events" to set picture of every desktop to ("/Users/shared/SISLogo/SIS_WP.jpg" as POSIX file as alias)'
exit 0
I have tried resetting permissions, using PPPC utility to ensure proper Jamf permissions. I get the user message when the script is run but no change to background. Anybody have an idea?

5 REPLIES 5

mm2270
Legendary Contributor III

The osascript portion must be run as the logged in user. Since Jamf Pro runs all scripts as root, it's failing.

Try this modification:

#!/bin/bash

loggedinuser=$(stat -f%Su /dev/console)
loggedinuid=$(id -u "$loggedinuser")

/bin/launchctl asuser "$loggedinuid" sudo -iu "$loggedinuser" /usr/bin/osascript -e 'tell application "System Events" to set picture of every desktop to ("/Users/shared/SISLogo/SIS_WP.jpg" as POSIX file as alias)'
exit 0

Also, when posting any kind of script here, be sure to select/highlight the entire script and click the >_ button in the post editing toolbar, so it encloses it in the script markdown and formats it properly for the forums.

Tjernigan
New Contributor III

@mm2270 OMG thank you, thank you, thank you.
Out of curiosity on single monitor systems I had used the script:

!/bin/bash

sudo osascript -e 'tell application "Finder" to set desktop picture to POSIX file "/Users/shared/SISLogo/SIS_WP.jpg"'
exit 0

And it changed the wallpaper fine for the primary display. Why did the osascript work in this instance but not for multi monitors?

mm2270
Legendary Contributor III

If you're saying the second script above for single monitor systems worked as is when deployed from Jamf Pro, then I can't explain that. Generally speaking, when talking about most Applescript/osascript commands that manipulate the user space, they have to be run as the user and not as root. Maybe the single monitor instance operates a little differently, and root is able to make those changes. I'm not sure though.

Tjernigan
New Contributor III

Ok. So now I am unable to get the request for permission box to not appear on the user machine. I have created a pppc permission for jamf.app, jamf, and jamf agent with all permissions allowed. I even downloaded the github pppc for system events and still the dialog box pops up. I have heard others having this issue and it's possibly a bug with Jamf?? anybody think anything else?

maurits
Contributor

Have you looked at desktoppr with outset in stead of osascript? Less issues with PPPC imho.