MacOS – Changing the background image in all spaces

command linedesktopmacosspaces

I'm running Max OSX Mountain Lion, 10.8.4. I have tried several solutions to change the background image in every space/desktop, but can only get one. I have tried this shell script, have tried using Python's appscript and have tried another shell script. It currently only changes the background in the current space.

This operation, changing the desktop background, can be done with a drag and drop method. However, I want to setup a cron job (or any other method) to have the wallpaper change randomly from images in a folder.

As of now, it looks like I just need to figure out how to access all desktops in argparse, as it currently works with one desktop/space. Unfortunately, the documentation is rather poor.

Best Answer

desktop 1 seems to be the currently selected space, so you might use a hack like this:

set f to POSIX file "/Library/Desktop Pictures/Beach.jpg"
tell application "System Events"
    repeat 4 times
        key code 123 using control down -- 123 is left arrow
    end repeat
    repeat 4 times
        set picture of desktop 1 to f
        key code 124 using control down -- 124 is right arrow
    end repeat
end tell

The entries in ~/Library/Preferences/com.apple.desktop.plist look like this:

default =                 {
    BackgroundColor =                     (
        0,
        0,
        0
    );
    Change = Never;
    ChangePath = "/Library/Desktop Pictures";
    ChangeTime = 1800;
    DrawBackgroundColor = 1;
    ImageFileAlias = <00000000 00980003 00000000 cca6c692 0000482b 00000000 0049cf53 0049cf7a 0000cc06 bed80000 00000920 fffe0000 00000000 0000ffff ffff0001 00080049 cf530044 e295000e 00140009 00420065 00610063 0068002e 006a0070 0067000f 00060002 00480044 00120022 4c696272 6172792f 4465736b 746f7020 50696374 75726573 2f426561 63682e6a 70670013 00012f00 ffff0000>;
    ImageFilePath = "/Library/Desktop Pictures/Beach.jpg";
    NewChangePath = "/Library/Desktop Pictures";
    NewImageFilePath = "/Library/Desktop Pictures/Beach.jpg";
    NoImage = 0;
    Placement = Crop;
    Random = 0;
};

I don't know how to get an alias as data for the ImageFileAlias key.