Pick of the Week - Nov 10 [Show all picks]
Path Finder 5 - A feature-laden Finder replacement
Submit Hint Search The Forums LinksStatsPollsFAQHeadlinesRSS
12,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 0.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (0 votes cast)
 
[5,829 views]  

Use an AppleScript to force a desktop picture change | 9 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 whomever posted them. This site is not responsible for what they say.
Backgrounds in Subfolders
Authored by: sveiki on Wed, Jun 11 2008 at 9:18AM PDT
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 Wed, Jun 11 2008 at 10:27AM PDT
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 Wed, Jun 11 2008 at 2:13PM PDT
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 Wed, Jun 11 2008 at 5:03PM PDT
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 Thu, Jun 12 2008 at 12:57AM PDT
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 Thu, Jun 12 2008 at 12:57AM PDT
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 Fri, Jun 13 2008 at 6:30PM PDT
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 Sat, Jun 14 2008 at 5:19PM PDT
great hint!

[ Reply to This | # ]
Use an AppleScript to force a desktop picture change
Authored by: JimMueller on Mon, Jun 16 2008 at 10:14AM PDT
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 | # ]