Posted on 12-06-2012 05:02 AM
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?
Posted on 12-06-2012 05:38 AM
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.
Posted on 12-06-2012 06:40 AM
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
Posted on 12-06-2012 06:52 AM
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
Posted on 12-06-2012 07:05 AM
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?
Posted on 12-06-2012 07:08 AM
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.
Posted on 12-06-2012 07:48 AM
@ Carl, we'd want this done as "Once".. :(
@MM2270, maybe.. but i guess distributing the plist using FEU/FUT would work too!
Posted on 12-06-2012 08:14 AM
@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.
Posted on 12-06-2012 11:25 AM
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.
Posted on 12-06-2012 03:09 PM
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:(
Posted on 12-13-2012 03:05 AM
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?
Posted on 04-05-2013 01:04 AM
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?
Posted on 04-05-2013 04:58 AM
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
Posted on 04-05-2013 05:24 AM
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.
Posted on 04-05-2013 05:42 AM
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.
Posted on 04-05-2013 10:01 AM
I think once per user per computer.
Posted on 04-05-2013 02:02 PM
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.
Posted on 04-05-2013 02:15 PM
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
Posted on 04-06-2013 12:39 AM
put all the pitures you want in a custom /Library/Desktop Pictures/ folder
Package it up with Composer
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
#!/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
#!/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}"
Posted on 04-06-2013 12:48 AM
Note if a user select a desktop background as a solid color rather than a picture then the desktop wallpaper doesnt change.
Posted on 04-08-2013 10:59 PM
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
Posted on 04-18-2013 06:43 AM
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`
Posted on 04-18-2013 07:14 AM
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)
Posted on 04-18-2013 07:30 AM
wow thanks Mike, thats really great :)
Posted on 04-18-2013 07:40 AM
Isn't that what I said?
Posted on 04-18-2013 07:44 AM
@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.
Posted on 04-18-2013 08:55 AM
Thanks anyway, my mind just went blank and i couldnt work it out after trying for ages lol
Posted on 04-22-2013 06:10 AM
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
Posted on 04-22-2013 08:49 AM
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>
Posted on 05-17-2013 08:18 AM
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}"
Posted on 05-31-2013 04:31 AM
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)
Posted on 06-01-2013 01:49 PM
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
Posted on 06-01-2013 10:08 PM
@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.