6

I have the following code to change the desktop image of my Macbook

tell application "System Events"
tell current desktop
set picture to "/Library/Desktop Pictures/Beach.jpg"
end tell
end tell

How do change all desktops - I have a second monitor.

5 Answers 5

8

The previous answers look great, but I wanted to share a way I found to do this with much less code.

tell application "System Events"
    tell every desktop
        set picture to "path/to/picture.png"
    end tell
end tell

You could even condense it to one line:

tell application "System Events" to tell every desktop to set picture to "path/to/picture.png"
1
  • instead of changing to specific image, u can also use set change interval to 1800 or whatever the amount of seconds the change should happen so u dont get stuck with the same image after u run the script.
    – ctf0
    Jul 18, 2022 at 15:11
5

Here's a little script I use to set most of the Desktop Background properties for my dual monitors:

tell application "System Events"
    tell desktop 1
        set pictures folder to "/Library/Desktop Pictures"
        set picture rotation to 2 -- using interval
        set change interval to 1800
        set random order to true
    end tell
    tell desktop 2
        set pictures folder to "/Library/Desktop Pictures/Mine"
        set picture rotation to 2 -- using interval
        set change interval to 1800
        set random order to true
    end tell
end tell

I use this because MacOSX often resets my backgrounds to the default.

2

This might work. I only have one monitor so couldn't properly test it.

tell application "System Events"
    set desktopCount to count of desktops
    repeat with desktopNumber from 1 to desktopCount
        tell desktop desktopNumber
            set picture to "/Library/Desktop Pictures/Beach.jpg"
        end tell
    end repeat
end tell
1
  • 1
    Is there a way to set the picture to "dynamic" mode on each desktop as well? For that matter... where is there a reference for all the available settings available for Desktop pictures, Screensavers, etc in AppleScript?
    – RCross
    Apr 14, 2020 at 8:24
0

For the Default monitor

osascript -e 'tell application "System Events" to set picture of current desktop to "<path-to-img>"'

For the second monitor

osascript -e 'tell application "System Events" to set picture of second desktop to "<path-to-img>"'
0

I do not have enough reputation to add this as a comment under @RobinKay's answer. I wanted to make a small correction and complement his answer with all the possible values for wallpaper rotation.

set picture rotation to 0 -- Disables rotation
set picture rotation to 1 -- Rotates images on specified interval
set picture rotation to 2 -- Rotates images at login time
set picture rotation to 3 -- Not sure about this one,
                             but I think it rotates images upon sleep/wakeup cycle

Ref: Scriptable System Preferences

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .