8

Summary. Automation changes desktop background for all (virtual) desktops, but no all monitors. How to do it for all monitors?

Details.

This blog entry discusses how to automatically change background for all (virtual / Mission Control / etc) desktops with following script:

#! /bin/bash
#script to change all desktop backgrounds
echo -n “Drag and drop an image file here then press ‘return’ or press ‘control-c’ to cancel…”
read -e WLPR;
function change_wallpaper
{
defaults write com.apple.desktop Background "{default = {ImageFilePath='$WLPR'; };}"; killall Dock
}
change_wallpaper

However, it doesn't change the desktop background on my 2nd monitor on my Lion-based system for any of my Mission-Controlled desktops. How does one apply above (or similar) to all physical monitors? (Hacks like this unattractive.)

1

I have dual monitor Mac at work so I will be able to give it a try tomorrow (day off today).

I think if you were to compare the output of:

$ defaults read com.apple.desktop

Before and after having manually changed the wallpaper via:

System Preferences > Desktop & Screen Saver > Desktop

That, should, bring up a window in the second display allowing you to select required image. Once that is setup and working, compare the output from the original command and see if it gives you any clues. I shall do the same tommorow and play around it with it. See if I can't give you a more complete answer.

0

I'm afraid this isn't a complete answer, since I haven't yet found a way to make this work with multiple desktops, but it will set the desktop of all monitors in the current space to whatever picture you specify.

on run {input, parameters}
    set theFile to first item of input
    tell application "System Events"
        set theDesktops to a reference to every desktop
        repeat with aDesktop in theDesktops
            set the picture of aDesktop to theFile
        end repeat
    end tell
    return theFile
end run

Add that to a Run AppleScript action in an Automator workflow, and save it as an application. You can then drag and drop an image onto the application and it will be set as the desktop image.

Perhaps someone can find a way to make this work with multiple spaces/desktops.

0

On my system (10.12) defaults read com.apple.desktop gave Domain com.apple.desktop does not exist

The following link gives me 2 ideas: https://derflounder.wordpress.com/2013/10/26/mavericks-desktop-background-picture-settings-moved-from-librarypreferencescom-apple-desktop-plist/

The 1st idea: Change the link of DefaultDesktop: Therefore you need to temporary disable System Integrity Protection (https://apple.stackexchange.com/a/214540/156148), to change the symlink under /System/Library/CoreServices/DefaultDesktop.jpg

#! /bin/bash
if [ -z "$1" ]; then
    echo "Please specify an absolute path to an image as first parameter"
    exit -1
fi
mv /System/Library/CoreServices/DefaultDesktop.jpg /System/Library/CoreServices/DefaultDesktop.jpg.backup
ln -s $1 /System/Library/CoreServices/DefaultDesktop.jpg

The 2nd idea:

#! /bin/bash
#script to change all desktop backgrounds
if [ -z "$1" ]; then
    echo "Please specify an absolute path to an image as first parameter"
    exit -1
fi

osascript -e "tell application \"System Events\" to set picture of every desktop to \"$1\""
killall Dock

You must log in to answer this question.

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