Sync random order Pictures on Multi Screen Desktops.

Apples built in ‘Change picture – random order’ option for your desktop Pictures is great.

Screen Shot 2014-11-12 at 21.17.41

But what happens if you have more than one Screen/Monitor.  Well each screen needs you to turn this on separately . And the pictures for each screen will be independently random from each other.

We can fix that using Applescript and LaunchAgents we can turn off  the above and make each desktop picture change to a random image at a set interval and be the same image on each desktop.

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.

Heres how..

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

1, Paste this script into a new Script Editor document.

Open script in Applescript Editor  Applescript Editor

 

#!/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 your 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

Hi, Please Leave a Reply