Category filter

Script to set desktop wallpaper for Mac

Device admins can set wallpapers remotely for endpoint devices by running a script. The following instructions will help you prepare the script that locates an image on the endpoint and sets it as the desktop wallpaper for the specified user. The script can be saved as a .sh file and executed on the managed device using Hexnode’s Execute Custom Script action.

Scripting language – Bash

File extension – .sh

Disclaimer:


The sample scripts provided below are adapted from third-party open-source sites.

Set desktop wallpaper

The above code uses the osascript command to run an AppleScript line.

path=”$1” – Reads the absolute location of the image file along with the file extension. The user folder specified on the path will be taken as the user for which the wallpaper is to be set and the user must be actively logged in while the script is executed. The argument $1 here must be entered while adding the script on the Execute Custom Script window.

type in the arguments inside the Arguments field

A sample path can be like – /Users/Admin/Pictures/new_Wallpaper.png

osascript –e – Runs the main AppleScript command from within the Shell environment.

tell application ‘Finder’ to set desktop picture to POSIX file “’”$path”’” – Use the ‘Finder’ app on the Mac to locate the image and set it as a desktop picture. The image location is given in the standard POSIX format.

The next lines set up an alert system to notify if the operation succeeded or failed. It follows the standard exit status of Bash.

When the script is initiated, a prompt appears at the endpoint device asking the user to allow the script to control Finder. Click OK button to allow the script to locate the image and set it as the wallpaper.

Notes:

  • Ensure that the path of the wallpaper specified in the script is valid to prevent errors.
  • It is recommended to manually validate the script execution on a system before executing the action in bulk.
  • Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.

  • Sample Script Repository