HomeHowTo › Changing The Background Of All Desktops On Mac OS

Changing The Background Of All Desktops On Mac OS

On Mac OS it is not possible to change the desktop background for all desktops at once. Instead, one has to manually configure the background on every single desktop which is quite annoying. I have written a little AppleScript which makes the background changing a bit easier.

Just copy this code into the AppleScript Editor, translate it and then save it as an application:

-- show file selection dialog to choose a wallpaper
set pic to choose file

-- ask for number of desktops/spaces
display dialog "Number of desktops (1-10): " default answer "1"
set desktops to text returned of result

-- switch to every desktop and change its wallpaper
repeat with n from 1 to desktops

-- set key code for the next desktop
if (n = 1) then set k to 18
if (n = 2) then set k to 19
if (n = 3) then set k to 20
if (n = 4) then set k to 21
if (n = 5) then set k to 23
if (n = 6) then set k to 22
if (n = 7) then set k to 26
if (n = 8) then set k to 28
if (n = 9) then set k to 25
if (n = 10) then set k to 29
-- switch to next desktop
tell application "System Events" to key code k using {control down}
delay 0.5
-- change wallpaper
tell application "Finder" to set desktop picture to pic
delay 0.5

end repeat

The app will open up a file selection dialog to let you choose the new wallpaper. Since it doesn’t seem to be possible to detect the number of desktops, the app will ask for it. Then it will execute keystrokes ( ctrl + <1-n> ) using the corresponding key codes for the numbers 1 to 0 on the keyboard to switch to every desktop and change its background. You might have to increase the delay to 1 if you encounter any problems. The “Change Picture” option in the desktop settings must be disabled.

Also, to make this work, the shortcuts for desktop switching must be activated under [System Preferences] -> [Keyboard] -> [Keyboard Shortcuts]:







This works on OS X 10.9.3 and newer.

2 Comments.[ Leave a comment ]

  1. It only changes on one screen, but how about dual screen setup??

  2. It doesn’t change for the 2nd screen on a dual screen setup, how to do that?!

Leave a Comment