Setting the Mac Desktop Wallpaper or Background on macOS 13

bcrockett
Contributor III

 

Greetings, 

Goal:

I have been trying different GitHub workflows created to automate the process setting and locking a desktop background image on a macOS computer. 

Problem Statement:

My core issue is after I use a workflow to install the image on the test computer. I cannot find a workflow to set that stored image file as a desktop background that works for me. 

 

Two examples:

 Example #1 Published this year for Intune. Not jamf pro but the workflows for scripts and configuration profiles should be MDM agnostic. 

Step one: Use a script to download the wallpaper. This works. 

Step two: use a .mobleconfig to set the wallpaper. This does not work for me and there are no readable logs so I am having difficulty debugging the problem with workflow. All I see on the test computer is the screen flash when the configuration profile is saved and after that, the desktop image stays the same. 

 

Example: 2

Armin Briegels desktoppr workflow. Last updated 05/2022

Step one: Install the image file to the client's computer by using composer to create a .pkg with the BoringBlueDesktop.png nested in the correct directory – /Library/Desktop Pictures/BoringBlueDesktop.png<

Step two: Install desktopper with script

Step three: set the desktop image: This script fails with a log entry of: 

###########

usage: sudo -h | -K | -k | -V

usage: sudo -v [-AknS] [-g group] [-h host] [-p prompt] [-u user]

usage: sudo -l [-AknS] [-g group] [-h host] [-p prompt] [-U user] [-u user]

            [command]

usage: sudo [-AbEHknPS] [-C num] [-D directory] [-g group] [-h host] [-p

            prompt] [-R directory] [-T timeout] [-u user] [VAR=value] [-i|-s]

            [<command>]

usage: sudo -e [-AknS] [-C num] [-D directory] [-g group] [-h host] [-p prompt]

            [-R directory] [-T timeout] [-u user] file ...





launchctl asuser "$uid" sudo -u "$currentUser" desktoppr /System/Library/CoreServices/DefaultDesktop.heic

###############

 

In this example, I was trying to use the script to set the default desktop. 

Armin notes in his comments within the script itself

####

 

# dropping the sudo will result in a warning that desktop seems to be

        # running as root, but it will still work

######

In my testing with this workflow this is my core roadblock. The log file on the script shows the command is run as root and needs to be run as the local user. 

 

Armin as a tool for this, In his 08/25/2020  blog post, he lists strategies for running scrips as a local user for things like desktop preferences. 

 

So for the next test, we install destoppr on the test computer. 

Then on the test computer itself run the following command in terminal: 

desktoppr /System/Library/CoreServices/DefaultDesktop.heic

This command works to change the desktop image to the default. 

 

Next, we use the same command arguments in a policy to run a terminal command from the files and processes option Execute command box. The command we use is as follows;

#######

launchctl asuser "$uid" sudo -u "$currentUser" desktoppr /System/Library/CoreServices/DefaultDesktop.heic

 

#########

Which should tell the client computer to use the power of the local user to set the desktop image to the Default Desktop. 

However, this fails, and my log output is as follows:

 

#######

usage: sudo -h | -K | -k | -V

usage: sudo -v [-AknS] [-g group] [-h host] [-p prompt] [-u user]

usage: sudo -l [-AknS] [-g group] [-h host] [-p prompt] [-U user] [-u user]

            [command]

usage: sudo [-AbEHknPS] [-C num] [-D directory] [-g group] [-h host] [-p

            prompt] [-R directory] [-T timeout] [-u user] [VAR=value] [-i|-s]

            [<command>]

usage: sudo -e [-AknS] [-C num] [-D directory] [-g group] [-h host] [-p prompt]

            [-R directory] [-T timeout] [-u user] file ...





launchctl asuser "$uid" sudo -u "$currentUser" desktoppr /System/Library/CoreServices/DefaultDesktop.heic

#################

I know the “

desktoppr /System/Library/CoreServices/DefaultDesktop.heic

” command works because when I run it terminal on the client device it changes the desktop to the default background. 

 

However, I can not figure out how to replicate this action in a terminal command sent from jamf pro in a policy. Or as a line in a script. 

 

Thanks for any troubleshooting support this community can provide. 

~ B

 

 

 

3 REPLIES 3

dmccluskey
Contributor

This is the script I used to set the wallpaper keep in mind this still allows the user to change it after it's been set if you're looking to lock it down you can use a configuration profile to do so.

Because this is an OSA script it requires Mac OS13 or newer to run.

 

#!/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:foldername:foldername2:wallpaper_General.jpg"} as alias
end tell
ENDofOSAscript
exit 0

 

2023-09-14_12-25-40.jpg

Ok, I tested the script with a notification set the alias as the default desktop photo;

 

 

 

#!/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 {"/System/Library/CoreServices/DefaultDesktop.heic"} as alias
end tell
ENDofOSAscript
exit 0

 

 

However, I get the following error in testing

 

########

Script result: 101:106: execution error: Can’t make {"Library/CoreServices/DefaultDesktop.heic"} into type alias. (-1700)

 

#######

Do you have any thoughts on why it is failing? 

 

Thanks, ~B

 

@dmccluskey thanks for the screenshot. 

 

I got it working using the default desktop photo with just the MDM Configuration profile -- Restrictions -- Functionality -- Lock Desktop Picture Path --

/System/Library/CoreServices/DefaultDesktop.heic

 

Scoped to my test device worked like a charm!

 

 

 

Screenshot 2023-09-14 at 2.27.17 PM.png

No scripts are needed.