Setting Wallpaper

marc_littlejohn
New Contributor II

Hi,

What would be the best way to set a wallpaper but allow the user to change it, I already have a config profile to enforce wallpapers on shared machines, but for our 1:1 machines I want to set a default wallpaper but allow the user to change it afterwards

24 REPLIES 24

andrew_nicholas
Valued Contributor

This discussion should shed some light on how to do it. If you want it to also apply to the current logged in user you can add something like this:

#!/bin/bash
currentUser=$(/bin/ls -l /dev/console | /usr/bin/awk '{print $3}')
sudo -u "$currentUser" -H osascript -e 'tell application "Finder" to set desktop picture to POSIX file "/path/to/file/name.jpg"'.

stevevalle
Contributor III

I found the easiest way to set the default desktop image to a branded custom image was to name it Sierra.jpg and change the name of the Sierra.jpg to Sierra 3.jpg.

The package we deploy:
b6f1e155fcbb4f0394b8d59df0d9626e

Wakko
Contributor

I found that using this approach works before for me. It points to a folder in which we deploy our assets too. This also allows users to change their background as well.

osascript -e 'tell application "System Events" to set picture of every desktop to ("/Library/XXXX/XXXX.jpg" as POSIX file as alias)'

marc_littlejohn
New Contributor II

Thanks. I only wanted to make this policy apply to newly enrolled devices so I made a smart group called "New Enrollments" and the criteria for this group is "Enrollment less than 1 day ago" and Scoped the policy only to this smart group

rosskivowitz
New Contributor

Hey @Echevarria,

I was hoping you might be able to help us out with this process. I don't know if you remember but you actually did our Jumpstart. We had a .pkg coupled with a script to replace the Sierra.jpg and rename the old file and then to subsequently set that wallpaper as the default on all users. However, we're running into some issues.

Are you able to go through it with me to detail how we can replace the default wallpaper with a .jpg of our choosing? Thanks in advance!

Ross

rderewianko
Valued Contributor II

Here's what we do.

Deploy pictures to the

/Library/Desktop Pictures

Folder

Then we run this script.

#!/bin/bash
# $3 is the logged in user - default for most policies.  
sudo -u $3 /usr/bin/osascript <<ENDofOSAscript
tell Application "Finder"
set the desktop picture to {"Library:Desktop Pictures:<jpgofpicturehere>.jpg"} as alias
end tell
ENDofOSAscript
exit 0

rosskivowitz
New Contributor

@rderewianko Thanks for that script. As a test, I manually placed a .jpg in that folder and then ran the script but didn't see anything occur - should I have? If I'm currently logged in as a user and then run that script, would I see the wallpaper change or can I not be logged in to see it take effect? I was testing it on a computer with Deep Freeze so I couldn't restart, but I can run it on another computer. Thanks for your help!

Ross

rderewianko
Valued Contributor II

When you ran the script did you edit it to the file you put on the machine? the line <jpgofpicturehere>.jpg needs to reflect the file name.

gabriel_cashman
New Contributor

@rderewianko Thank you for the script!!! Worked like a charm and was a fun alternative to setting the macOS Desktop Background using a Configuration Profile.

As an alternative for maybe a lab computer try this!

Workflow:
Configuration Profile: Install Automatically --> Computer Level
Restrictions Payload: Functionality Tab --> Lock Desktop Picture --> /Library/Desktop Pictures/Thor.jpg (or whatever JPG/file path)
Scope --> All Computers or specific groups

Save and watch the magic!

Configuration Profiles are SWIFT and unforgiving or to quote a good friend of mine... Persistent and authoritative.c015e7f787024b60a7dcb3a34f3e85d0

scottb
Honored Contributor

Is there any way to modify this to apply a wallpaper to ALL connected displays @rderewianko ?
We have a client that wants them applied to all connected displays on Macs and PC's.
TIA
The base script works great - Thank you.

fabian_fasshube
New Contributor III

I've been looking for a way a long time now, which would work smoothly in any situation. I did change the wallpaper on my machine and did make a "Desktop Pattern" snapshot with Jamf Composer.
In addition to that, I did also include the wallpaper into the same "Desktop Pattern" and since it is in the user folder, I did create a dmg file.
Uploaded it via Jamf Admin, published it with "FUT" and "FEU".
After installing the Desktop Pattern DMG, I simply kill the dock "killall Dock" and that's it.

P.s. If you'd like to change the lock screen as well, please set a script before, which removes the cache file "rm -rf /Library/Caches/com.apple.desktop.admin.png "

Hope this helps

DirkM
Contributor

Anybody tried this on Mojave where osascript causes a message like

xxx would like to control the application “Finder”

to appear?

Hugonaut
Valued Contributor

@dmatth01

In System Preferences -> Security & Privacy -> Accessibility "Allow the apps below to control your computer"

The applescript app has to be there in order to avoid the dialog, this was a fix in 10.13 & up.... i believe a lot of people have ran into this problem.

The problem lies in the tcc.db and not being able to write sql too it anymore....i am not aware of an easy workaround..i've been scouring the internet for it as well.. I hope this helps! (Forgive me if this is innaccurate information as we have not yet moved from High Sierra to Mojave in my organization, so my knowledge is limited to 10.13)

here are some other discussions for reference

https://www.jamf.com/jamf-nation/discussions/24910/programmatically-set-accessibility-for-an-app-in-security-and-privacy

https://www.jamf.com/jamf-nation/discussions/29295/allowing-security-privacy-privacy-accessibility-allow-the-apps-below-to-control-your-computer

________________
Looking for a Jamf Managed Service Provider? Look no further than Rocketman

sullrich
New Contributor III

Does this script get around the TCC/Mojave prompt?

https://github.com/grahamgilbert/macscripts/blob/master/set_desktops/set_desktops.py

DirkM
Contributor

The question is how do I get the app (which is a shell script running in terminal launched during the initial enrollment) in there to make the wallpaper actually appear after enrollment? I don't want to force a specific wallpaper, just set the initial one that the user can change.

Hugonaut
Valued Contributor

@dmatth01

for our enrollment process I created a package with a new wallpaper named "High Sierra.jpg" that is placed in the Desktop Picture directory and overwrites the apple default wallpaper

Location "/Library/Desktop Pictures/High Sierra.jpg"

you can always rename the Default to a new name and save it as well in the event a user likes the default but this way you get your institutions wallpaper by default and no need for a config profile to lock it down and the user can then change the wallpaper.

________________
Looking for a Jamf Managed Service Provider? Look no further than Rocketman

paperfixie
New Contributor II

@Hugonaut did you just do a Composer snapshot for this or was it a package with the image as the payload and a script to perform the copy?

Hugonaut
Valued Contributor

@vmascoli For our Mojave Prestage I used composer and packaged it, deploys during prestage enrollment so it is there once you login.

a method I have also used features oasascript deployed by jamf for putting in place forced profiles but it all works the same you can just path the script on the fly of course. this is if you have a webserver setup though.

#!/usr/bin/osascript

set UNAME to "username"
set PASSW to "password"

try
    do shell script "mkdir /Library/DirectoryHere/" user name UNAME password PASSW with administrator privileges
end try

try
    do shell script "curl -o /Library/DirectoryHere/WallpaperHere.jpg  http://server.com/wallpapers/Wallpaper.jpg" user name UNAME password PASSW with administrator privileges
end try
________________
Looking for a Jamf Managed Service Provider? Look no further than Rocketman

DFree
New Contributor III

Just thought I'd add what I just setup today (and tested it on High Sierra 10.13.6), using various bits I found on Jamf Nation if someone else can use it. I couldn't get it to reliably work with the other scripts I saw. Oh well.

Created a Policy that has:

  • The package created with Snapshot like what @stevevalle did above.

  • The script from @andrew.nicholas (repeated below) to force the the desktop image to change. (Not sure if it works on multiple displays...I hope it does, but its not the end of the world.)

#!/bin/bash

currentUser=$(/bin/ls -l /dev/console | /usr/bin/awk '{print $3}')
sudo -u "$currentUser" -H osascript -e 'tell application "Finder" to set desktop picture to POSIX file "/Library/Desktop Pictures/High Sierra.jpg"'
  • The script from @fabian.fasshuber (repeated below) to remove the login image (macOS will create a new one on logout.)
#!/bin/sh

rm -rf /Library/Caches/com.apple.desktop.admin.png

paperfixie
New Contributor II

@Hugonaut So it's placed in the Attachments section and gets run by being part of the Prestage?

Lotusshaney
Contributor II

Use this

https://github.com/scriptingosx/desktoppr

It’s great and does not use AppleScript so no problems with PPPC.

Also can control multi screens

dmaestre
Release Candidate Programs Tester

Great stuff. But, how do I center the image on the desktop and pad it with a crayon specific color?

rpayne
Contributor II

@Lotusshaney are you doing anything specific for Mojave/Catalina? We use DEPnotify for our deployments and as part of it we install wallpapers to the default folder and set them via $ desktoppr "/Library/Desktop Pictures/specific background.jpg". It flashes for a second then goes back.

msw-sa
New Contributor III

@rpayne I was able to get desktoppr working on M1 Big Sur devices. I used this postinstall script from the desktoppr github as a guide: https://github.com/scriptingosx/desktoppr/blob/master/examples/postinstall

The basic method recommended in that script is sudo -u "$loggedInUser" launchctl asuser "$uid" "$desktoppr" "$picturepath", but the sudo -u "$loggedInUser" piece doesn't appear to work on Big Sur; dropping the sudo piece and running launchctl asuser `id -u $3` $desktoppr "/path/to/desktop-background.png" in a script payload does. It throws a warning, "desktoppr is running as root. This is probably not what you are intending. To set the desktop picture for a user, desktoppr needs to run as that user." but it works nevertheless.