script to change wallpaper

I am looking for a way (script or porgram) to change my wallpaper selection based on what my IP is (like home or work) but also change the image randomly every hour or so (still making sure not to show a work image at home or a home image at work). Any one have idea ideas on how to do this?

Mac OS X (10.5.6)

Posted on Dec 26, 2008 11:25 AM

Reply
5 replies

Dec 26, 2008 3:16 PM in response to hennaheto

Sorry I have never touched applescript before


in this case you might want to learn a little apple script if you'll be using a script like that. There are probably several ways to do what you want but the following should work.

paste the following into Script Editor (it's in /Applications/Utilities).

<pre style="
font-family: Monaco, 'Courier New', Courier, monospace;
font-size: 10px;
margin: 0px;
padding: 5px;
border: 1px solid #000000;
width: 720px; height: 335px;
color: #000000;
background-color: #ADD8E6;
overflow: auto;"
title="this text can be pasted into the Script Editor">
property ip_address : ""

set cur_ip to do shell script "ifconfig |grep inet |tail -1 | awk '{print $2}'"

if cur_ip is not equal to ip_address then -- check to see if the ip address has changed since last check. if it didn't - do nothing.

set ip_address to cur_ip

if ip_address = "home.ip.address" then


tell application "System Events"
-- RANDOM ROTATION OF A FOLDER OF IMAGES
tell current desktop
set picture rotation to 1 -- (0=off, 1=interval, 2=login, 3=sleep)
set random order to true
set pictures folder to file "path:to:home:images:"
set change interval to 3600.0 -- seconds
end tell
end tell
else if ip_address = "work.ip.address" then

tell application "System Events"
-- RANDOM ROTATION OF A FOLDER OF IMAGES
tell current desktop
set picture rotation to 1 -- (0=off, 1=interval, 2=login, 3=sleep)
set random order to true
set pictures folder to file "path:to:work:images:"
set change interval to 3600.0 -- seconds
end tell
end tell

end if

end if

</pre>


put the ip addresses of at home and at work in the above, as well as the corect paths to different folders with images. then save the script in your Documents folder. Call it, say, backgrounchanger. Then download [lingon|http://www.tuppis.com/lingon> and use it to make a launch daemon. make it run, say, every minute and execute the following command (enter it on line 2)

osascript /users/username/documents/backgroundchanger.scpt

Put your short user name instead of username in the above.
save the daemon and log out/in to activate it.

Dec 26, 2008 12:15 PM in response to hennaheto

there is certainly nothing ready made that would do this but it should be pretty easy with apple script.
see this link for details on how to script desktop preferences.
http://www.apple.com/applescript/features/system-prefs.html

you can get the current ip address with the following terminal command

ifconfig |grep inet |tail -1 | awk '{print $2}'

then set the background preferences based on the outcome of the command. you might have a problem though if the IP addresses are dynamic and change overtime.

Dec 26, 2008 12:51 PM in response to V.K.

Thanks for the welcome =) this looks like a really good resource to get questions answered. It looks pretty easy on that link you showed me I found
"tell current desktop
set picture rotation to 1 -- (0=off, 1=interval, 2=login, 3=sleep)
set random order to true
set pictures folder to file "Mac OS X:Library:Desktop Pictures:Plants:"
set change interval to 5.0 -- seconds
end tell
end tell"

which in combination with your code looks like it will do exactly what i need. Now were do i save/put this code? Sorry I have never touched applescript before

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

script to change wallpaper

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.