Skip to main content
Solved

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


Forum|alt.badge.img+18
  • Esteemed Contributor
  • 831 replies

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

Best answer by guillaumegete

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 original
Did this topic help you find an answer to your question?

7 replies

Forum|alt.badge.img+7
  • Valued Contributor
  • 69 replies
  • August 20, 2019

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

Forum|alt.badge.img+18
  • Author
  • Esteemed Contributor
  • 831 replies
  • August 20, 2019

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

Gabe Shackney
Princeton Public Schools


Forum|alt.badge.img+13

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""

Forum|alt.badge.img+18
  • Author
  • Esteemed Contributor
  • 831 replies
  • August 20, 2019

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

Gabe Shackney
Princeton Public Schools


Forum|alt.badge.img+8
  • Contributor
  • 22 replies
  • Answer
  • August 20, 2019

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


Forum|alt.badge.img+18
  • Author
  • Esteemed Contributor
  • 831 replies
  • July 21, 2021
guillaumegete wrote:

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


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


rpayne
Forum|alt.badge.img+11
  • Contributor
  • 124 replies
  • April 13, 2022
guillaumegete wrote:

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


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


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings