Category filter

Script to Set Desktop Wallpaper for Mac

Device admins can set wallpapers remotely for endpoint devices by running a script with Hexnode’s Execute Remote Script action for Mac. 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 with Hexnode.

Device admins can remotely run scripts on Macs managed with Hexnode using the 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.

Notes:

  • 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