Desktop Background

bentoms
Release Candidate Programs Tester

Hi All,

I've been asked to set the desktop background ONCE on all clients (10.6 - 10.8).

These are AD users, so no MCX due to https://my.jamfsoftware.com/discussion.html?id=4953..

I'd also like it set for both the Mac's screen & external display (where applicable).

I'm thinking i just grab a copy of ~/Library/Preferences/com.apple.desktop on a MacBook with an external screen that has the desktops set as i'd like them.. then deploy the plist using FEU/FUT's.

Thoughts?

32 REPLIES 32

jarednichols
Honored Contributor

Looks like the only thing that would get whacked would be the desktop picture changing preferences. But, since you're setting this once you probably don't care about that.

Mauricio
Contributor III

Hi Ben

You can create a policy with 'Execution Frequency' Once per User with the following AppleScript:

tell application "System Events" to set picture of every desktop to {"Macintosh HD:Library:Desktop Pictures:Andromeda Galaxy.jpg"} as alias

where "Macintosh HD:Library:Desktop Pictures:Andromeda Galaxy.jpg" is the path to the image you want.

Let me known if you need further assistace
Regards
Mauricio

bentoms
Release Candidate Programs Tester

Thanks Maurico, but this will only work once per user.. if the user changes mac it will not work:

https://jamfnation.jamfsoftware.com/featureRequest.html?id=45

mm2270
Legendary Contributor III

Oh yeah, that issue.
So, I wonder if it would work it you deployed this as a user launchagent + script combo to all existing users and the User Template, but designed it where the script disabled the LaunchAgent after it runs and destroys the script. That way it would run the next time any user on any Mac logged in, even if they change Macs and thus their home directory gets created from the User Template, but it would really only run once and remove itself.

Could that work?

cbrewer
Valued Contributor II

Setting the desktop background with Casper MCX works fine. I have 2 policies, one for 10.5/10.6 and one for 10.7/10.8. My 10.6 policy is set to User Level Enforced and my 10.7/10.8 policy is set to User Level Every Login.

bentoms
Release Candidate Programs Tester

@ Carl, we'd want this done as "Once".. :(

@MM2270, maybe.. but i guess distributing the plist using FEU/FUT would work too!

mm2270
Legendary Contributor III

@bentoms- Lol, yeah, I guess I'm over thinking it a bit. Probably easiest to just deploy the plist with FEU/FUT as you originally suggested and be done with it.

JRM
Contributor

We just replace the default image with what we want users to have. You could make a copy of the galaxy image if you want to keep the galaxy as an option.

tkimpton
Valued Contributor II

Hi Ben matey

On 10.8 I created a symbolic link from galaxy to actually point to the pic I wanted. Works fine. So for a pkg that run 10.6 to 10.8 I did my normal thing for 10.6 plus for 10.8 created a symbolic link. I then created a pkg combining the two and now they both work :)

Sorry for vagueness had a few beers:(

bentoms
Release Candidate Programs Tester

Thanks all, the requirements have now changed :(

We've got a folder of images that they wish to have set as a desktop background @ login randomly.. i can use MCX for 1 screen.. but not sure how to do this with a second screen as they seem to have some unique identifier.. any ideas?

tkimpton
Valued Contributor II

Hi Ben

Ive got the same requirement passed my way. They want a folder with different images and want them changed randomly and want it working on a second screen.

Did you overcome this at all and what did you do in the end?

chris_kemp
Contributor III

Geez, the things people come up with... <shakes head>

I ran into the second screen issue here, with a bunch of dual-screen Mac Pros. Every one of them had to be manually done, until I figured out replacing the default graphic files with a new one (named Aurora.png).

Is this a one-off randomization, or do they want it to constantly change?

How about this for a hack: name your images 1, 2, 3, etc., then have a script pick a random number and do something like 'cp $num.png /path/to/Aurora.png'

Geez, I need to go home & go to bed... :-P

tkimpton
Valued Contributor II

Thanks Chris i like the idea

This is currently what i do as a postflight script after the picture gets installed.

# Link the Desktop Picture to Galaxy.Jpg
ln -sf /Library/Desktop Pictures/Rufus Leonard/RL_2010_Wallpaper_2560x1600.jpg /Library/Desktop Pictures/Galaxy.jpg

Im thinking to still do this intially to a constant image for the imaging.

Then possibly use your to suggestion as a mechanism to change them randomly some how.

If it doesnt work im not going to loose sleep over it and they will just have to use one picture.

mscottblake
Valued Contributor

Are you needing once per user per computer or just once per computer?

I would set up some sort of shell script change the default user template then to loop through all users on the machine and set it. I would set this script to run once per computer.

tkimpton
Valued Contributor II

I think once per user per computer.

bentoms
Release Candidate Programs Tester

Sorry for not updating this.

The only way i could set the desktop for all screens was either replacing the default (thanks for the tip on that Tim btw!) or by using an AppleScript with the below command..

osascript -e 'tell application "System Events" to set picture of every desktop to "/Library/Desktop Pictures/Galaxy.jpg"'

Issue is you get a delay from logging in to the screen getting set.

tkimpton
Valued Contributor II

Thanks for that. I've just finished and successfully tested random pictures changing and it's sweet.

Unfortunately I have an unrelated problem I need to attend to now so I will post it when I can

tkimpton
Valued Contributor II
  1. put all the pitures you want in a custom /Library/Desktop Pictures/ folder

  2. Package it up with Composer

  3. Add this preflight script

#!/bin/sh
## preflight
##
## Not supported for flat packages.

pathToScript=$0
pathToPackage=$1
targetLocation=$2
targetVolume=$3

# Move Apples Desktop pictures by renaming the folder
mv /Library/Desktop Pictures/ Apple Desktop Pictures/


exit 0      ## Success
exit 1      ## Failure
  1. Add a postflight script
#!/bin/sh
## postflight
##
## Not supported for flat packages.

pathToScript=$0
pathToPackage=$1
targetLocation=$2
targetVolume=$3

# Make a symbolic link to trick Apples default wallpaper so if the changing doesnt kick in at least we get a default picture!
ln -sf /Library/Desktop Pictures/RL_2013_Desktop_Pattern-11.jpg /Library/Desktop Pictures/Galaxy.jpg

# Console user
user=`ls -l /dev/console | cut -d " " -f4`

# Change the wallpaper in applescript
command=`/usr/bin/osascript <<EOT
tell application "Finder"
        set desktop picture to (some file of (path to desktop pictures folder))
end tell
EOT`

 Remove the users desktop plist
su - "${user}" -c 'rm -rf ~/Library/Preferences/com.apple.desktop.plist'

# Pause 3 seconds
sleep 3

# Change the Wallpaper as the console user
su - "${user}" -c "${command}"

exit 0      ## Success
exit 1      ## Failure
  1. Make a script called Wallpaper Changer with
#!/bin/bash
# Console user
user=`ls -l /dev/console | cut -d " " -f4`

# Change the wallpaper in applescript
command=`/usr/bin/osascript <<EOT
tell application "Finder"
        set desktop picture to (some file of (path to desktop pictures folder))
end tell
EOT`

 Remove the users desktop plist
su - "${user}" -c 'rm -rf ~/Library/Preferences/com.apple.desktop.plist'

# Pause 3 seconds
sleep 3

# Change the Wallpaper as the console user
su - "${user}" -c "${command}"
  1. Upload the script to your jss and create a policy to run offline every hour etc

tkimpton
Valued Contributor II

Note if a user select a desktop background as a solid color rather than a picture then the desktop wallpaper doesnt change.

tkimpton
Valued Contributor II

i changed the postflight script to add your line in Ben because it didnt always change immediately, but now it does :)

#!/bin/sh
## postflight
##
## Not supported for flat packages.

pathToScript=$0
pathToPackage=$1
targetLocation=$2
targetVolume=$3

# Make a symbolic link to trick Apples default wallpaper
ln -sf /Library/Desktop Pictures/RL_2013_Desktop_Pattern-11.jpg /Library/Desktop Pictures/Galaxy.jpg

# Console user
user=`ls -l /dev/console | cut -d " " -f4`

# Remove the users desktop plist
su - "${user}" -c 'rm -rf ~/Library/Preferences/com.apple.desktop.plist'

# Set Galaxy to the picture
osascript -e 'tell application "System Events" to set picture of every desktop to "/Library/Desktop Pictures/Galaxy.jpg"'

# Pause 10 seconds
sleep 10

# Change the wallpaper in applescript
command=`/usr/bin/osascript <<EOT
tell application "Finder"
        set desktop picture to (some file of (path to desktop pictures folder))
end tell
EOT`

# Change the Wallpaper as the console user
su - "${user}" -c "${command}"

exit 0      ## Success
exit 1      ## Failure

tkimpton
Valued Contributor II

unfortunately this part of my script only changes the main display and doesnt change a secondary one. Does anyone know how i can also randomly change the secondry display image?

# Change the wallpaper in applescript
command=`/usr/bin/osascript <<EOT
tell application "Finder"
set desktop picture to (some file of (path to desktop pictures folder))
end tell
EOT`

mm2270
Legendary Contributor III
tell application "System Events"
    set picture of every desktop to (some file of (path to desktop pictures folder)) as alias
end tell

The above seems to work for me (10.8.3)

tkimpton
Valued Contributor II

wow thanks Mike, thats really great :)

bentoms
Release Candidate Programs Tester

Isn't that what I said?

mm2270
Legendary Contributor III

@bentoms, yeah pretty much. :) Only difference is you had specified an exact image file whereas Tim wanted it choosing an image randomly from his Desktop Pictures folder. But besides that, its really the same thing. I take no credit, I simply cobbled together a few different bits of code from this thread and ran it through AppleScript Editor to test it.

tkimpton
Valued Contributor II

Thanks anyway, my mind just went blank and i couldnt work it out after trying for ages lol

tkimpton
Valued Contributor II

On my machine this works fine

#!/bin/bash

# Change the Desktop background

/usr/bin/osascript <<EOT
tell application "System Events"
set picture of every desktop to (some file of (path to desktop pictures folder)) as alias
end tell
EOT

on others i get error 54:61: syntax error: Expected class name but found application constant or consideration. (-2741)

hmmmm

tkimpton
Valued Contributor II

i decided to put my ~/Library/Preferences/com.apple.desktop.plist as a DMG with FEU and FUT. It works ok and puts the main display as random every 30 minutes but not a secondary display.

<?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>Background</key>
    <dict>
        <key>spaces</key>
        <dict>
            <key></key>
            <dict>
                <key>0</key>
                <dict>
                    <key>DSKDesktopPrefPane</key>
                    <dict>
                        <key>ChangeTime</key>
                        <real>1800</real>
                        <key>Random</key>
                        <true/>
                        <key>UserFolderPaths</key>
                        <array>
                            <string>/Library/Desktop Pictures</string>
                        </array>
                    </dict>
                    <key>ImageFilePath</key>
                    <string>/Library/Desktop Pictures/Galaxy.jpg</string>
                    <key>NewImageFilePath</key>
                    <string>/Library/Desktop Pictures/Galaxy.jpg</string>
                </dict>
                <key>default</key>
                <dict>
                    <key>Change</key>
                    <string>TimeInterval</string>
                    <key>ChangePath</key>
                    <string>/Library/Desktop Pictures</string>
                    <key>ChangeTime</key>
                    <real>1800</real>
                    <key>Random</key>
                    <true/>
                </dict>
            </dict>
        </dict>
    </dict>
</dict>
</plist>

tkimpton
Valued Contributor II

This worked for me to run as a login policy to make sure the settings are enforced to change desktop pictures and even works with dual monitors

#!/bin/bash

# Console user
user=`ls -l /dev/console | cut -d " " -f4`

command=`/usr/bin/osascript <<EOT
try
tell application "System Events"
set picture of every desktop to (some file of (path to desktop pictures folder)) as alias
set change interval of every desktop to 1800
set picture rotation of every desktop to 1
set random order of every desktop to true
end tell
end try
EOT`

# Change the Wallpaper as the console user
su - "${user}" -c "${command}"

tkimpton
Valued Contributor II

does any one know how i can run my script as osascript through the shell?

Im still having errors

syntax error: Expected class name but found application constant or consideration. (-2741)

tkimpton
Valued Contributor II

Decided to create and Applescript app with the commands and then run this script at login

#!/bin/bash

######## ENVIRONMENT VARIABLES ##############

# Console user
user=`ls -l /dev/console | cut -d " " -f4`

# Specify the file
file=/Library/Management/Applications/ChangeDesktopBackground.app

# Command to run
command=`open /Library/Management/Applications/ChangeDesktopBackground.app`

######### DO NOT MODIFY BELOW THIS LINE ###########

# If the file exists run the command
if [ -f $file ] ;then

# open the app as the console user
su "${user}" -c '$command'

fi
exit 0

evarona
New Contributor II

@tkimpton - responding to this comment

does any one know how i can run my script as osascript through the shell?

I've recently had success using something like this:

#!/bin/bash
echo '
tell application "System Events"
    -- insert the rest of your Applescript here 
end tell
 ' > /Library/Scripts/MyScript.applescript

CONSOLEUSER=`ls -l /dev/console | cut -d " " -f4`
su - "${CONSOLEUSER}" -c 'osascript /Library/Scripts/MyScript.applescript'

I'm using this to remove "Disable Screen Saver" in Expose (security requirement). It works most of the time but I have seen the same 2741 errors. I'll look into your idea of compiling it. Thanks for that.