Best workflow for Changing wallpaper

MMartin1
New Contributor II

I know this has been resolved. But I'm looking for the best workflow for changing but now locking the wallpaper for my user's machines during the provisioning process

25 REPLIES 25

Hugonaut
Valued Contributor II

Step 1. Create a Package containing the Wallpaper (pathed to a hidden location/directory) you wish to use for the end users computer. Set to deploy during enrollment scoped to your zerotouch computers.

Step 2. Create a Configuration Profile for Computers.

Step 3. Configuration Profile -> Restrictions -> Functionality -> Check "Lock Desktop Picture" & Enter the path.

Step 4. Scope to Computers in Zerotouch Process. During enrollment, before login this change will (SHOULD) take effect.

Step 5. Save & Done

**If you need to use the Restrictions Configuration Profile Payload for anything else, you should configure everything else that restrictions covers as well - an all in one payload is required as the most restrictive is what the computer uses and you will run into conflicts if you scope multiple config profile payloads with the same options

9910553ddb14401ba2aa0fc096311b3c

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


Virtual MacAdmins Monthly Meetup - First Friday, Every Month

MMartin1
New Contributor II

@Hugonaut Can it be done without locking it??

Hugonaut
Valued Contributor II

Yes you can do that but that is a different process - I detailed a solution here - https://www.jamf.com/jamf-nation/discussions/24457/setting-wallpaper

Basically, choose the wallpaper you want, rename it to "High Sierra.jpg" then, start composer take a before snapshot, once the snapshot is complete move your "High Sierra.jpg" into the "/Library/Desktop Pictures" directory replacing "/Library/Desktop Pictures/High Sierra.jpg" then take the after snapshot, obviously parse out & remove everything besides Library -> Desktop Pictures -> High Sierra.jpg from the aftershot & create the package. Then create a policy with that package, scope it to the users & flag it to deploy during enrollment.

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


Virtual MacAdmins Monthly Meetup - First Friday, Every Month

This worked for us as well, had to make sure to run the script that runs as logged in user, linked in the github proj. I have found while running scripts the line below is particularly helpful, replacing <insert path to script> with the path to your script may even work without this app.

# test if a user is logged in
if [ -n "$loggedInUser" ]; then
    # Run script as end user
    uid=$(id -u "$loggedInUser")
    launchctl asuser "$uid" sudo -u <insert path to script>
else
    echo "no user logged in, Cannot Run Script"
fi




ryan_s
New Contributor II

@Chris or whomever ... this is probably going to sound like a dumb question, but what do I do with desktoppr once I download from Github? The ReadMe doesn't mention the set up of desktoppr from what I can find; there are examples of how to use AFTER things have been put in-place, but I'd imagine I need to put these files somewhere specific in order to use the commands.

tuinte
Contributor III

@ryan.s

Installing the desktoppr package means you now have a new command line tool.

desktoppr /path/to/image.png

That command will make image.png the desktop background.

So you need to deploy both the desktoppr package and image.png to every machine, then send that command. There are different strategies for doing this at scale, but could feasibly be done in one policy with two packages (desktoppr and the image) and a Files & Processes payload with the command entered in Execute Command. Frequency set to once per user per computer.

Test first.

ryan_s
New Contributor II

@tuinte -- Forgive me as I must be overlooking something simple. I get that I need to deploy it, but I guess that is what my question is. I have the below files...how do I deploy the files and in which directory do they belong? (i.e. no DMG or PKG that I can see here). I see the zsh in the github; do I execute this on a Mac and then deploy its PKG to all our managed workstations?

desktoppr.xcodeproj changed compiler version back to 4.2 for compatibilty pre 10.14.4   4 months ago
desktoppr   added extra output in case of failure   4 months ago
examples    added some missing quotes, thanks to shellcheck last month
.gitignore  various commits, kinda works    4 months ago
LICENSE added license and readme    last year
README.md   Update README.md    last year
pkgAndNotarize.zsh  added extra output in case of failure

tuinte
Contributor III

@ryan.s

On the GitHub page, near the bottom, there's a link to a page where you can download the installer. It points to the releases page here.

That's Package 1, to install desktoppr.

Package 2 you'll have to create with Composer, Packages, or some other pkg-creating tool. You'll want your desired desktop background in that package. Technically, it can be placed anywhere on the machine, but somewhere accessible but not temporary like /Users/Shared might be a good idea.

Upload both packages to Jamf.

Create a new script in Jamf with the following:

#!/bin/bash

##
## sets the desktop using `desktoppr`
##

# set the path to the desktop image file here
picturepath="/Library/Desktop Pictures/BoringBlueDesktop.png"

# verify the image exists
if [[ ! -f "$picturepath" ]]; then
    echo "no file at $picturepath, exiting"
    exit 1
fi

# verify that desktoppr is installed
desktoppr="/usr/local/bin/desktoppr"
if [[ ! -x "$desktoppr" ]]; then
    echo "cannot find desktoppr at $desktoppr, exiting"
    exit 1
fi

# get the current user
loggedInUser=$(/usr/bin/python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "
");')

# test if a user is logged in
if [[ $loggedInUser != "" ]]; then
    # get the uid
    uid=$(id -u "$loggedInUser")
    # do what you need to do
    launchctl asuser "$uid" "$desktoppr" "$picturepath"
else
    echo "no user logged in, no desktop set"
fi

Change the "picturepath" variable in the script to the path of the image in your Package 2.

Create a new policy and add both PKGs and the script to it. The script should be set to run AFTER. Once per user per computer. Scope to a test machine.

Login to any user on the test machine to have the policy run. Login to another to have it run again.

That's one way to do it. Any trouble, let us know.

ryan_s
New Contributor II
It points to the releases page here.

Ah, perfect! I was completely overlooking that link on the GITHUB page. Thank you for the response!

bizzaredm
Contributor

Does desktoppr work without any popups? and could someone explain to me how it avoids them?

PEGS_JAMF_Suppo
New Contributor II

Hey everyone

We are trying to implement Desktoppr as per above. But we are having issues with it recognising the currently logged in user. From what I can see, when we push the policy to the device, it is using the admin account associated in JAMF, not the logged in user account.

We are getting this error: Script result: 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.

The desktop picture will change for the admin account, but not anyone else that logs in (script is executing as per each user who logs in).

Any help or advice would be appreciated.

dstranathan
Valued Contributor II

@PEGS_JAMF_Support I have seen this behavior too. But I have also seen this error message when it Successfully worked for a non-admin account, too. Confusing.

Still wish we could set a custom wallpaper for the login window. In Catalina.

arminBriegel
New Contributor III
New Contributor III

@PEGS_JAMF_Support I have seen this myself. I believe the reason is, that in Catalina something in behavior of launchctl asuser has changed. The solution is to use sudo -u instead. (In this case that works, I have found other situations where you abosulutely need launchctl asuser, it is confusing.)

I have updated the sample scripts at https://github.com/scriptingosx/desktoppr/tree/master/examples

dstranathan
Valued Contributor II

@arminBriegel Changing from 'launchctl asuser' to 'sudo -u' did the trick for me. Thanks!

jimmy-swings
Contributor II

'sudo -u' isn't working over here on Catalina 10.15.4.

Using @arminBriegel postinstall as an example, the command 'sudo -u' executes without error however with no result (ie. the desktop image isn't being replaced).

Executing the command 'sudo -u "$loggedInUser" "$desktoppr"' also returns an incorrect result.

root# sudo -u "$loggedInUser" "$desktoppr" 0
/System/Library/CoreServices/DefaultDesktop.heic

test-user# "$desktoppr" 0
/Library/Application Support/Organisation Files/Desktop Images/april.jpg

arminBriegel
New Contributor III
New Contributor III

@jaz It works for me. Both from the script within a pkg and interactively from the command line, even when I open a root session with sudo -i

How are you obtaining your $loggedInUser and are you sure a user is logged in when the command runs?

I have used

launchctl asuser "$uid" sudo -u "$loggedInUser" /path/to command

in some situations. Though I haven't needed this for desktoppr yet.

dan_berlyoung
New Contributor III

Has anyone figured out how to add a folder to the list of desktop sources in the Desktop & Screen Saver preference pane? I'm using Desktoppr to set the initial desktop just fine but I want to hook in the folder with a bunch of alternatives so they see them when opening that pane. I found another article from 5 years ago that set something via 'defaults write' but that doesn't seem to work under Big Sur.

Philein
New Contributor III

@arminBriegel i'm trying to make it works but on 11.2.3 i'm not able to change the background.
I used your script:

#!/bin/sh

##
## sets the desktop using `desktoppr`
##

export PATH=/usr/bin:/bin:/usr/sbin:/sbin

# set the path to the desktop image file here
picturepath="/Users/Shared/CBA Wallpapers/CBA 4K 2C.jpg"


# verify the image exists
if [ ! -f "$picturepath" ]; then
    echo "no file at $picturepath, exiting"
    exit 1
fi

# verify that desktoppr is installed
desktoppr="/usr/local/bin/desktoppr"
if [ ! -x "$desktoppr" ]; then
    echo "cannot find desktoppr at $desktoppr, exiting"
    exit 1
fi

# get the current user
loggedInUser=$( echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ && ! /loginwindow/ { print $3 }' )

# test if a user is logged in
if [ -n "$loggedInUser" ]; then
    # set the desktop for the user
    uid=$(id -u "$loggedInUser")
    launchctl asuser "$uid" sudo -u "$loggedInUser" "$desktoppr" "$picturepath"
else
    echo "no user logged in, no desktop set"
fi

But i obtain this result and nothing change:

Successfully installed Wallpapers_v.1.pkg.
Running script Set Wallpaper Desktoppr...
Script exit code: 0
Script result: 
Running command desktoppr /Users/Shared/CBA Wallpapers/CBA 4K 0A.jpg...
Result of command:
desktoppr: a tool to set the desktop picture
  usage: desktoppr [all|main|N] [/path/to/image]
         all:        all screens (default)
         main:       main screen
         N: (number) screen index
         if a valid file path is given it will be set as the desktop picture,
         otherwise the path to the current desktop picture is printed

         The next two values will be set for _all_ screens.
         color:      provide a hex color string (000000 to FFFFFF) for the background
         scale:      fill | stretch | center | fit
                     determines how the image is scaled to the screen
Checking for patches...
No patch policies were found.

arminBriegel
New Contributor III
New Contributor III

Looks to me that you have this policy configured with a script and and a run command.

The "Run command" is what's failing because there are spaces in an unquoted file name.

I cannot tell from this log why the script is not setting the desktop, though. Check, if the image file exists at that path and at the time the script runs, and the privileges are set so that it is readable by the user.

bigben54
New Contributor III

Having trouble using the hex color feature here. Modified version of example below, that first sets the image to transparent.png and then uses $4 for the hex.

Output below that... using "00FFFF" in script parameter 4 in my policy example. It completes without error and replaces current image, but is always just black and not setting a "background color".

Same if i invoke locally as user... anyone having success with 11.2.3 and hex?

#!/bin/sh

##
## sets the desktop using `desktoppr`
##

export PATH=/usr/bin:/bin:/usr/sbin:/sbin

# declare
colorinhex="$4"
transparentimage="/Library/Desktop Pictures/transparent.png"

# verify that desktoppr is installed
desktoppr="/usr/local/bin/desktoppr"
if [ ! -x "$desktoppr" ]; then
    echo "cannot find desktoppr at $desktoppr, exiting"
    exit 1
fi

# get the current user
loggedInUser=$( echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ && ! /loginwindow/ { print $3 }' )

# test if a user is logged in
if [ -n "$loggedInUser" ]; then
    # set the desktop for the user
    uid=$(id -u "$loggedInUser")

    echo "running $desktoppr $transparentimage as user"
    launchctl asuser "$uid" sudo -u "$loggedInUser" "$desktoppr" "$transparentimage"

    echo "running $desktoppr color $colorinhex as user"
    launchctl asuser "$uid" sudo -u "$loggedInUser" "$desktoppr" color "$colorinhex"
else
    echo "no user logged in, no desktop set"
fi
ben@Bens-MacBook-Pro ~ % sudo jamf policy -event desktophex Password: Checking for policies triggered by "desktophex" for user "ben"... Executing Policy DesktopHEX Downloading desktoppr-0.4.pkg... Downloading https://use1-jcds.services.jamfcloud.com//download/556e6e90c6964ce1b341b334f987c941/desktoppr-0.4.pkg?token=7c55f817387f4b2d8686541427c038f82us92q7hx3cdkz8bae7d1iw7wzq3x4v2... Verifying package integrity... Installing desktoppr-0.4.pkg... Successfully installed desktoppr-0.4.pkg. Running script setDesktopHex... Script exit code: 0 Script result: running /usr/local/bin/desktoppr /Library/Desktop Pictures/transparent.png as user running /usr/local/bin/desktoppr color 00FFFF as user Submitting log to https://company.jamfcloud.com/ ben@Bens-MacBook-Pro ~ % /usr/local/bin/desktoppr color 00FFFF ben@Bens-MacBook-Pro ~ %

Thanks!

trandall
New Contributor II

Any success with modifying the script? I'm trying to set a stretched background and this appears to be on the right track for the edit I would need to do to achieve it. 

Release Desktop image settings · scriptingosx/desktoppr · GitHub

Update: desktoppr v0.3 – Scripting OS X

cwcampb
New Contributor III

Is there a way to omit admins from getting the desktoppr image ? I'm just using the example script can someone add the line in to omit admin users? Thank you!

!/bin/sh

## sets the desktop using `desktoppr`

export PATH=/usr/bin:/bin:/usr/sbin:/sbin

set the path to the desktop image file here

picturepath="/Library/Desktop Pictures/BoringBlueDesktop.png"

verify the image exists

if [ ! -f "$picturepath" ]; then echo "no file at $picturepath, exiting" exit 1
fi

verify that desktoppr is installed

desktoppr="/usr/local/bin/desktoppr"
if [ ! -x "$desktoppr" ]; then echo "cannot find desktoppr at $desktoppr, exiting" exit 1
fi

get the current user

loggedInUser=$( echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ && ! /loginwindow/ { print $3 }' )

test if a user is logged in

if [ -n "$loggedInUser" ]; then # set the desktop for the user uid=$(id -u "$loggedInUser") launchctl asuser "$uid" sudo -u "$loggedInUser" "$desktoppr" "$picturepath"
else echo "no user logged in, no desktop set"
fi

Desktoppr worked for us as well, had to make sure to run the script that runs as logged in user, linked in the github proj. However, I have found while running scripts (likely will work with the osascript lines) the line below is particularly helpful, replacing "<insert path to script>" with the path to your script may even work without this app. Hope this helps!

 

# test if a user is logged in
if [ -n "$loggedInUser" ]; then
    # Run script as end user
    uid=$(id -u "$loggedInUser")
    launchctl asuser "$uid" sudo -u <insert path to script>
else
    echo "no user logged in, Cannot Run Script"
fi

 

Geissbuhler
Contributor

Desktoppr worked for us as well, had to make sure to run the script that runs as logged in user, linked in the github proj. However, I have found while running scripts (likely will work with the osascript lines) the line below is particularly helpful, replacing "<insert path to script>" with the path to your script may even work without this app. Hope this helps!

 

 

 

# test if a user is logged in
if [ -n "$loggedInUser" ]; then
    # Run script as end user
    uid=$(id -u "$loggedInUser")
    launchctl asuser "$uid" sudo -u <insert path to script>
else
    echo "no user logged in, Cannot Run Script"
fi