applescript desktop image question

Discussion in 'Mac Programming' started by otg123, Feb 10, 2010.

  1. otg123 macrumors newbie

    Joined:
    Feb 10, 2010
    #1
    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.
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    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.
     
  3. otg123 thread starter macrumors newbie

    Joined:
    Feb 10, 2010
    #3
    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...
     
  4. otg123 thread starter macrumors newbie

    Joined:
    Feb 10, 2010
    #4
    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
    
     
  5. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #5
    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.
     
  6. otg123 thread starter macrumors newbie

    Joined:
    Feb 10, 2010
    #6
    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
     
  7. mysterytramp macrumors 65816

    mysterytramp

    Joined:
    Jul 17, 2008
    Location:
    Maryland
    #7
    Is your second if...then block necessary?

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

    mt
     
  8. otg123 thread starter macrumors newbie

    Joined:
    Feb 10, 2010
    #8
    @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
    
     

Share This Page