Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Use an AppleScript to force a desktop picture change System
I have my desktop images set to change every 30 minutes in random order. Sometimes the desktop will display an image that displayed earlier in the day, and I wanted a way to 'advance' the image easily. The following AppleScript will cause the desktop image to change, in whatever order you have set, each time it is run:
property theSwitch : 0
if theSwitch = 0 then
  tell application "System Events"
    tell current desktop
      set change interval to 1801.0
    end tell
  end tell
  set theSwitch to 1
else
  tell application "System Events"
    tell current desktop
      set change interval to 1800.0
    end tell
  end tell
  set theSwitch to 0
end if
To maintain your current change interval, modify the change interval lines to reflect your interval, measured in seconds. Thus, for my 30-minute setting, I used 1801 and 1800 seconds. One hour would be 3601 and 3600, etc. For this script to work, you must have both Change Picture and Random Order enabled on the Desktop tab of the Desktop & Screen Saver System Preferences panel.

[robg adds: This works as described, and is also useful if you just don't happen to like whatever image was randomly chosen. Save the script as an application and drop it somewhere easy to access for a one-click solution. In my case, I put it into a Butler AppleScript action, and assigned it a keyboard shortcut for a no-click solution. I had to change the script somewhat to make it work in Butler, and my image actually toggles twice -- I basically had to remove all the theSwitch references and loops, leaving just two tell application loops.]
    •    
  • Currently 2.25 / 5
  You rated: 3 / 5 (8 votes cast)
 
[11,002 views]  

Use an AppleScript to force a desktop picture change | 10 comments | Create New Account
Click here to return to the 'Use an AppleScript to force a desktop picture change' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Backgrounds in Subfolders
Authored by: sveiki on Jun 11, '08 09:18:52AM

What I really want to do (but don't have the time at the mo' to code) is to find a way to do desktop background changing but where I specify a folder and potential images are taken from that folder and from subfolders. I've tried doing this with a smart folder, and it doesn't seem to work.



[ Reply to This | # ]
Backgrounds in Subfolders
Authored by: musselrock on Jun 11, '08 10:27:04AM
You might find your answer here:

http://www.apple.com/applescript/features/system-prefs.html

A script demonstrating how to set the desktop to display a folder of images in random sequence


[ Reply to This | # ]
Use an AppleScript to force a desktop picture change
Authored by: billabOng on Jun 11, '08 02:13:12PM

typing 'killall Dock' in the terminal will also change your desktop image.



[ Reply to This | # ]
Use an AppleScript to force a desktop picture change
Authored by: stauf on Jun 11, '08 05:03:37PM
To switch all your desktops, and doesn't require you to edit the script at all for interval, I used a repeat loop instead of just 'tell every desktop' in case the intervals are different per screen:
property theSwitch : 0

tell application "System Events"
	set desktopnames to get display name of every desktop
end tell

if theSwitch = 0 then
	tell application "System Events"
		repeat with currentdesktop in desktopnames
			tell (every desktop whose display name is currentdesktop)
				set initInterval to get change interval
				set change interval to initInterval + 1
			end tell
		end repeat
	end tell
	set theSwitch to 1
	
else
	tell application "System Events"
		repeat with currentdesktop in desktopnames
			tell (every desktop whose display name is currentdesktop)
				set initInterval to get change interval
				set change interval to initInterval - 1
			end tell
		end repeat
	end tell
	set theSwitch to 0
end if


[ Reply to This | # ]
Use an AppleScript to force a desktop picture change
Authored by: sachxn on Jun 12, '08 12:57:01AM

Wow it worked well for me in the first go itself.

---
Sachin



[ Reply to This | # ]
Use an AppleScript to force a desktop picture change
Authored by: sachxn on Jun 12, '08 12:57:57AM
Wow it worked well for me in the first go itself.

---
Sachin

[ Reply to This | # ]

Use an AppleScript to force a desktop picture change
Authored by: Volt on Jun 13, '08 06:30:01PM

This is Leopard-only, right? It doesn't compile or run for me on Tiger, but I don't see it marked as "10.5".



[ Reply to This | # ]
Use an AppleScript to force a desktop picture change
Authored by: V.K. on Jun 14, '08 05:19:23PM

great hint!



[ Reply to This | # ]
Use an AppleScript to force a desktop picture change
Authored by: JimMueller on Jun 16, '08 10:14:06AM

This reminds me of a discussion here several years ago about a script to display the filename of the current desktop. AFAIR, it was never made to reliably work.
I am not saying that this script's code reminds me of the previous one.
I'm just saying that this reminds me to try to resurrect that old discussion - especially since our newer, burlier hardware lets us stuff thousands of images in our "random desktops" folder and frequently my wife and I look at each other's screens and ask each other "Oooh! I haven't seen that - is it new? What is it?" and we have to wade through our respective folders and trade files. Yes, I know it is a problem of our own making...



[ Reply to This | # ]
Use an AppleScript to force a desktop picture change
Authored by: allentown on Mar 14, '10 06:00:33PM

I am not sure why this has to be so verbose and complicated. I made a simple script that has been tested on Snow Leopard.

It assumes that you have
[X] "change picture ever x timesteps"
[X] Random Order

My current settings are 15 minutes, but I find the randomizer to lean on the edges, never giving me pictures from the middle.

tell application "System Events"
	tell current desktop
		set initInterval to get change interval -- get the currrent display interval
		set change interval to -1 -- force a change to happen right now
		set change interval to initInterval -- change it back to the original display interval
	end tell
end tell

What this does is gets the current setting of your change interval in seconds, so my 15 minutes will return 900. That is set to a variable of initInterval. I then set the change interval to -1, which will force an immediate change of the desktop image. Finally, I set it back to the original change interval.

I have tied this to an action in LaunchBar. And you may find that at times it is not set back to your original change interval. You can add in a "Delay 3" to right before the line that sets it back to the original change interval, which will solve that.

For me, LaunchBar will be stuck for that 3 seconds, which bothers me, so I sick with it, and if I see my desktop image changing repeatedly, I know to go fix it.

[ Reply to This | # ]