How to make this automator action?
June 30, 2006 7:16 PM   Subscribe

Tearing my hair out over automator and applescript.

I'm trying to create an action that will change my desktop background: display photos of morning scenes in the morning, evening scenes in the evening, day scenes in the day, etc.

I've glue-sticked together an applescript that will find out the time and and put it in a variable as one of three words: morning, day, evening and night.

set TheDate to current date
set theDateText to TheDate as text
set theTime to time of TheDate
set theHour to theTime div 3600

if theHour > 6 and theHour < 11 then set thename to morning end if if thehour> 10 and theHour < 19 then set thename to day end if if thehour> 18 and theHour < 23 then set thename to evening end if if thehour> 22 then
set theName to "night"
end if

if theHour < 7 then set thename to night end if/code>


But I can't for the life of me figure out how to get that variable into the next automator step, even though I have folders in ~/Backgrounds named "morning" "day" "evening" and "night" full of flickr images ready and waiting the be fetched randomly and plugged into automator's built-in "set as desktop background" step. I can get "day" (or "evening" or whatever) to get entered into spotlight, but that doesn't do much good.

(It would be even cooler if someone knew of a way to pull the photos straight from flickr, but that sounds hard. I am, it should be obvious at this point, not a programmer at heart.)
posted by Tlogmer to Computers & Internet (8 answers total)
 
Wow. That applescript worked on preview. Here it is as a text file.
posted by Tlogmer at 7:19 PM on June 30, 2006


make the last line of the script

get thename

This casuse the result of the script to be the value of this variable. This should be passed on to the next step in Automator.
posted by kindall at 8:07 PM on June 30, 2006


This should work:
on run {input, parameters}    set foldername to "whatever"        set fullpath to "Macintosh HD:path:to:folder:" & foldername & ":"        tell application "Finder" to set piclist to every item of folder fullpath        set n to number in piclist        set picpath to item (random number from 1 to n) of piclist as string        return (POSIX path of picpath) as string    end run
But because Applescript and/or Automator suck, it doesn't. It does return a path, but the desktop picture doesn't change. For some reason, if you paste that path into the source code as a string, so that the script returns exactly the same thing it does work. I give up.
posted by cillit bang at 8:24 PM on June 30, 2006


Kindall: Sorry, bad phrasing on my part. I can get it to the next automator action (using apple's default applescript-in-automator framework, though your way's cleaner) but the only action I can find that will accept the string is Spotlight -- and spotlight won't pass it on to finder.

cillit: hm. Maybe I should get back to attempting to learn objective-C.
posted by Tlogmer at 8:46 PM on June 30, 2006


Ok, this works:
on run {input, parameters}    set theName to "pics"        set fullpath to "Macintosh HD:path:to:folder" & theName & ":"        tell application "Finder" to set piclist to every item of folder fullpath        set n to number in piclist        set filename to name of item (random number from 1 to n) of piclist        return "/path/to/folder/" & theName & "/" & filename    end run
Replace the first line with your code and change the paths on the second and last lines to wherever your folders are (and yes, you need to use two different path formats, such is the magic of Applescript).
posted by cillit bang at 9:01 PM on June 30, 2006




Shit, beaten to the punch.
posted by Tlogmer at 9:05 PM on June 30, 2006


set fullpath to "Macintosh HD:path:to:folder" & theName &":"
should be
set fullpath to "Macintosh HD:path:to:folder:" & theName &":"

posted by cillit bang at 9:05 PM on June 30, 2006


« Older how to hide the long boxes?   |   How can I improve my parking skills? Newer »
This thread is closed to new comments.