Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

otg123

macrumors newbie
Original poster
Feb 10, 2010
5
0
Hello,

I am using OS X Snow Leopard. I want to write a simple application or applescript that when run will check the current image used for the desktop picture and then based on which picture is being used, change it. If the picture being used is work.jpg, I want the picture to change to any random picture from the folder Pictures/Play. If the picture being used is not work.jpg, I would like the script to revert back to the work.jpg image. In other words, I simply want to toggle back and forth between work.jpg and any random picture in the Pictures/Play folder each time the app/script is run.

Thanks for any help you can offer.
 
Do you know AppleScript at all? If not, might be the time to learn. Otherwise you're not going to get very far, unless someone does all the work for you.
 
Wow... Didn't quiet expect that kind of a response.

I am very new to mac, but have programmed quite a bit in the PC world. I am certainly not looking for someone to write something for me.

Anyway, I have this almost written at this point, having it swap images now... all that's left is to work out the random part...
 
Finished. Here's what I did...

Code:
tell application "Finder"
	select window of desktop
	set curDesktop to (get desktop picture as text)
	if curDesktop is equal to "OSX:Users:ME:Pictures:work.jpg" then
		set randomImage to some file of folder "OSX:Users:ME:Pictures:Play"
		set desktop picture to randomImage
	else
		if curDesktop is not equal to "OSX:Users:ME:Pictures:work.jpg" then
			set desktop picture to "OSX:Users:ME:Pictures:work.jpg"
		end if
	end if
end tell
 
Apologies if I came across as rude, that wasn't my intention.

Your post was worded very much like you were speccing out your program for a quote. You gave no indication that you already were working on it, that you had any experience with programming, or that you began researching the basics on your own. So that didn't give me much to go on.
 
I did say "I want to write" in my first post, but it's ok... I realize you must have a lot of people dropping by to request code to be written for them. I could have been a little more detailed... Nonetheless, apology accepted.

Anyway, thanks at least for replying to my thread.. BTW: I like your avatar... anyone who has an affinity for little fury critters can't be all that bad. ;-)

Take Care,
OTG
 
Is your second if...then block necessary?

You might also need a colon at the end of the string you set to randomImage.

mt
 
@mt - Thanks for your feedback. Yes, 2nd if/then was unnecessary. Revised code:

Code:
tell application "Finder"
	select window of desktop
	set curDesktop to (get desktop picture as text)
	if curDesktop is equal to "OSX:Users:ME:Pictures:work.jpg" then
		set randomImage to some file of folder "OSX:Users:ME:Pictures:Play:"
		set desktop picture to randomImage
	else
		set desktop picture to "OSX:Users:ME:Pictures:work.jpg"
end tell
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.