4

I have a Macbook Air (with OS X 10.10 Yosemite). I've set the wallpaper to a folder and let the wallpaper change randomly every 30min. When I work at my desk, I have an additional external Display, and what I want is that that screen has the same wallpaper like the main display.

Is there a way to do this or do I miss an option?

  • I have updated the Answer to fix an issue – markhunte Nov 9 '14 at 17:00
  • Did you check your settings in the in system prefs. were off when running my answer. I have tested it on three Mac setups and it does what you want on all of them? – markhunte Nov 15 '14 at 12:29
  • You have to turn them off for both displays each has its on preference window – markhunte Nov 15 '14 at 12:32
4
+25

From the Preference pane I do not think you can do it.

But I just wrote an applescript that works on both my displays.

---------- UPDATE:

I was having a problem with the LaunchAgent loading on login.

Thislooks like it was because the system was trying to compile it and failing.

So I have updated the Answer to fix this by using a compiled Applescript instead of a plain text.


NOTE: you must turn off the change picture settings in the system prefs when running this script. Otherwise you will get the right results.

Each desktop changes to the same image. If I switch to a new space on a desktop it's image will change when the time comes.

There are couple of ways to run the script.

But in my opinion using LaunchAgents is the best way.

This answer may look complicated but should only take a minute to set up and start using.

1, Create paste this script into a new Script Editor document.

#!/usr/bin/osascript

tell application "System Events"
    (*Get a list of images in the pictures folder*)
    set DPFolder to ((POSIX file "/Library/Desktop Pictures") as alias)
    set DP to every file of DPFolder
end tell

(*get a random number limited to the count of the image count in the pictures folder*)
set randomNumber to random number (count of DP)

    tell application "System Events"

        (*get each desktop*)
        set theDesktops to a reference to every desktop

        (* repeat with each desktop*)
        repeat with i from 1 to (count theDesktops)

            (* Change the picture to the random image*)
            set picture of item i of the theDesktops to (POSIX path of (item randomNumber of DP))
        end repeat
    end tell

2, change the path in the line

set DPFolder to ((POSIX file "/Library/Desktop Pictures") as alias)

to contain your pictures folder if it is not the standard one. Make sure what ever folder you use only has images in and no other type of file or folder.

3, Save the document file format as a Script file (scpt)


enter image description here


4, In Terminal.app type:

chmod +x /Users/USERNAME/path/to/your/foo.scpt

chmod +x will make the file executable. Chang the path to the path of your script file.

5, In TextEdit.app

Open a new Plain text document and paste:

     <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.markosx.randomDesktopImage</string>
    <key>ProgramArguments</key>
    <array>
        <string>usr/bin/osascript</string>
       <string>/Users/USERNAME/path/to/your/foo.scpt</string>
    </array>
    <key>StartInterval</key>
    <integer>60</integer>
<key>KeepAlive</key>
    <false/>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>

Change the line:

/Users/USERNAME/path/to/your/foo.scpt

to contain the real path to your script file.

Change the line:

<integer>60</integer>

to contain the number of seconds you want the interval between runs.


enter image description here


6, save the file with the extension .plist in your users LaunchAgent folder.

~/Library/LaunchAgents

7, Now in terminal type and run:

  launchctl load ~/Library/LaunchAgents/foo.plist

Replace foo.plist with you real plist file name.

This will load the launchAgent to the system and start it running.

Or you can log out and back in.

To unload the launchAgent

launchctl unload ~/Library/LaunchAgents/foo.plist

  • Thanks markhunte, interesting approach. I can confirm it changes the wallpaper on both screens. However, with different images. So it does not really do what I want :-/ – Daniel Nov 13 '14 at 9:05
  • It does do what you want on my screens both have the same image. The script can only do that did you turn of the settings in system prefs. ? – markhunte Nov 13 '14 at 13:51
  • My main mac is on Yosemite. And with a slight change just to get the posix path on a 10.6 mac with two displays I get both desktops displaying the same image. I think you must have something in the desktop sys prefs running also. – markhunte Nov 13 '14 at 14:09
  • @Daniel test on another Mac. The same as all my other tests. – markhunte Nov 13 '14 at 14:18

You must log in to answer this question.

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