Set Wallpaper with commands in Terminal possible?

Hi,


I am looking for a way to set the wallpaper on Mac OS Ventura 13.3.1 (a) from the command line in Terminal. This will then allow me to use a script to deploy to all Macs and set it automatically.


I have tried all the suggestions I have found online, but none of them work on the latest Mac OS versions.


Any ideas?


Best regards

MacBook Pro (M2, 2022)

Posted on May 12, 2023 7:33 AM

Reply
Question marked as Best reply

Posted on May 12, 2023 8:58 AM

Launch Automator. Click New Document, select Workflow, and then click Choose. From the Files & Folders library, drag and drop Set the Desktop Picture action to the right onto the larger workflow window. Save and name it something memorable (e.g. setDesktopPix.workflow) to your preferred location (e.g. Desktop).


In your SHELL dot file, enter this function definition:


wallpaper () { automator -i "${1}" ~/Desktop/setDesktopPix.workflow }


save the dotfile, and to make the function immediately available, where dotfile may be one of zshrc, bashrc, or bash_profile:


source ~/.dotfile


You can then change the wallpaper with an appropriate image type:


wallpaper ~/Downloads/DSC_0005.NEF


Tested: macOS Ventura 13.3.1 (a) and Zsh 5.9.

10 replies
Question marked as Best reply

May 12, 2023 8:58 AM in response to justusewindows

Launch Automator. Click New Document, select Workflow, and then click Choose. From the Files & Folders library, drag and drop Set the Desktop Picture action to the right onto the larger workflow window. Save and name it something memorable (e.g. setDesktopPix.workflow) to your preferred location (e.g. Desktop).


In your SHELL dot file, enter this function definition:


wallpaper () { automator -i "${1}" ~/Desktop/setDesktopPix.workflow }


save the dotfile, and to make the function immediately available, where dotfile may be one of zshrc, bashrc, or bash_profile:


source ~/.dotfile


You can then change the wallpaper with an appropriate image type:


wallpaper ~/Downloads/DSC_0005.NEF


Tested: macOS Ventura 13.3.1 (a) and Zsh 5.9.

May 17, 2023 7:46 AM in response to justusewindows

I have one 32-in display and no other connected, but try the following Automator workflow which should quickly set the same passed wallpaper to all of your detected displays. Again, tested on Ventura 13.3.1 (a).




Code:


(*
 allDesktops.workflow
 
 Set same wallpaper image on all Desktops.
 
 automator -i full/path/to/wallpaper_img allDesktops.workflow
*)

use framework "Foundation"
use framework "AppKit"
use AppleScript version "2.4" -- Yosemite or later
use scripting additions

property ca : current application
property nil : a reference to missing value

on run {input, parameters}
	
	set desktopImg to ca's NSString's stringWithString:(POSIX path of (item 1 of input) as text)
	set desktopURL to ca's NSURL's fileURLWithPath:desktopImg
	
	set nswork to ca's NSWorkspace's sharedWorkspace()
	-- get all detected screens into an array
	set allScreens to ca's NSScreen's screens()
	
	repeat with ascreen in allScreens
		(nswork's setDesktopImageURL:desktopURL forScreen:ascreen options:nil |error|:0)
	end repeat
	
	return input
end run


I have also identified how one can pass a different wallpaper image for each display into a modified version of this workflow.

May 17, 2023 5:28 AM in response to VikingOSX

Thanks again, VikingOSX.

One question on that: Could you also set the background without altering the shell dotfile? I like to keep things as clean as possible and this includes the dotfiles. I think it should be possible to call the automator file directly from the zsh shell?


EDIT:

I figured out you can just copy both files (the automator script and the image file) into the same folder, for example /var/tmp/ and then execute this command with the particular path of both files and it works!


automator -i "/var/tmp/2560x1600-background-hd-wallpaper-s001.jpeg" /var/tmp/setDesktopPix.workflow

Sep 8, 2023 10:54 PM in response to VikingOSX

Hey VikingOSX, I appreciate you taking the time to share all this!


I'm a newbie at Automator coding, so I marvel at your handiwork above. What I'm facing is the annoying 'feature' of MacOS reverting to default wallpaper after even a minor OS update. This is so annoying as I use 10x Spaces across two monitors, with each Space having a unique picture as wallpaper. I have to reselect each Space wallpaper from scratch, together with preferred Centering and background colour choices.


Now THAT is what I would like to script up!


Any thoughts? I'm also running Ventura, v13.5.2


Many thanks,

Michael Abboud

Set Wallpaper with commands in Terminal possible?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.