Set a desktop Pic using script (profile won't let user change it)

GabeShack
Valued Contributor III

Trying to run this as the user but im losing my mind:

 osascript -e 'tell application "Finder" to set desktop picture to POSIX file "/Library/Desktop Pictures/Solar Gradients.heic

I just want to wrap that in a shell and have it use the logged in user to run it. I know I've done this before...but I can't seem to do it right now.

Ive been playing with profiles managing the desktop pic, however this seems to lock it and won't let the user change it which Im not fond of.
Any other solutions would be wonderful if anyone has any.
Gabe Shackney
Princeton Public Schools

Gabe Shackney
Princeton Public Schools
1 ACCEPTED SOLUTION

guillaumegete
New Contributor III

You may want to have a look at the desktoppr tool. Very useful, I deploy it everywhere, much better than dealing with AppleScript intricacies :)

View solution in original post

7 REPLIES 7

khey
Contributor

edit: crap you need the set the desktop instead..

try below script?

i vaguely remember that you need to run sudo killall cfprefsd to apply the changes.

#!/bin/sh

# grab current user
curUser=`ls -l /dev/console | cut -d " " -f 4`

# grab the system's uuid
if [[ `ioreg -rd1 -c IOPlatformExpertDevice | grep -i "UUID" | cut -c27-50` != "00000000-0000-1000-8000-" ]]; then
    macUUID=`ioreg -rd1 -c IOPlatformExpertDevice | grep -i "UUID" | cut -c27-62`
fi

#jamf displayMessage -message $curUser
defaults write /Users/$curUser/Library/Preferences/ByHost/com.apple.screensaver.$macUUID.plist PrefsVersion -int 100

# Use below to deploy custom screensaver
#defaults write /Users/$curUser/Library/Preferences/ByHost/com.apple.screensaver.$macUUID.plist moduleDict -dict moduleName "SOMETHING" path "/path/to/file" type -int 1

chown "$curUser" "/Users/$curUser/Library/Preferences/ByHost/com.apple.screensaver.$macUUID.plist"

sudo killall cfprefsd

#allow all users access to Folder where the Screensaver is
chmod -R 0777 /path/to/file

GabeShack
Valued Contributor III

Maybe I can wrap my AppleScript in your shell script though.
Thanks for the fast reply!

Gabe Shackney
Princeton Public Schools

Gabe Shackney
Princeton Public Schools

andrew_nicholas
Valued Contributor

This should get you what you're looking for.

#!/bin/sh

picLoc="/Path/To/Your/Wallpaper.jpg"
currentUser=$(/bin/ls -l /dev/console | /usr/bin/awk '{print $3}')

#Replace the Current Picture
sudo -u "$currentUser" -H osascript -e "tell application "Finder" to set desktop picture to POSIX file "$picLoc""

GabeShack
Valued Contributor III

@andrew.nicholas Thanks so much...seems to work perfectly in testing.

Gabe Shackney
Princeton Public Schools

Gabe Shackney
Princeton Public Schools

guillaumegete
New Contributor III

You may want to have a look at the desktoppr tool. Very useful, I deploy it everywhere, much better than dealing with AppleScript intricacies :)

GabeShack
Valued Contributor III

@guillaumegete This is actually what we are using now and works perfectly. Thanks!

Gabe Shackney
Princeton Public Schools

We were using this to great result. Now with the removal of python, it no longer works. We are failing with:

Script result: /Library/Application Support/JAMF/tmp/WGU Wallpaper: line 24: /usr/bin/python: No such file or directory
no user logged in, no desktop set