Working with lists

Posted on
Mon Feb 23, 2004 8:08 pm
gregjsmith offline
Posts: 946
Joined: Apr 01, 2003
Location: Rio Rancho, NM

Working with lists

I'm using the following applescript in WeathermanX:

Code: Select all
tell application "WeatherManX"
   set t to Forecast
end tell


the result is this:

Code: Select all
{{"Tonight", "Periods of rain showers before 11pm, then periods of snow between 11pm and 5am, then occasional rain and snow showers after 5am. Chance for precipitation is 90%. Cloudy, with a low near 34. Windy, with a east wind between 18 and 26 mph, with gusts as high as 37 mph.  New snow accumulation of less than one inch possible.", "p40"}, {"Tuesday", "Occasional rain and snow showers, mainly before 11am. Chance for precipitation is 80%. Mostly cloudy, with a high near 45. North northwest wind between 9 and 18 mph.  New snow accumulation of less than one inch possible.", "p29"}, {"Tuesday Night", "A 10 percent chance of snow showers before 11pm. Mostly cloudy, then gradually becoming mostly clear, with a low around 28. North northwest wind between 6 and 13 mph.", "p34"}, {"Wednesday", "Partly cloudy, with a high near 52. North northwest wind between 8 and 14 mph.", "p03"}, {"Wednesday Night", "Partly cloudy, with a low around 28. North northwest wind between 9 and 11 mph.", "p35"}, {"Thursday", "Partly cloudy, with a high around 57. North northwest wind between 9 and 17 mph.", "p03"}, {"Thursday Night", "A 20 percent chance of showers. Mostly cloudy, with a low near 36.", "p40"}, {"Friday", "A 20 percent chance of showers. Mostly cloudy, with a high around 53.", "p13"}, {"Friday Night", "A 20 percent chance of showers. Mostly cloudy, with a low around 35.", "p40"}}


I want to parse this out to see if it's going to rain. What format is this in exactly and how would I use it?

Posted on
Mon Feb 23, 2004 8:27 pm
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

Re: Working with lists

Hi Greg,

That is a list of lists. Try something like this:

repeat with dayForcast in forcastList
   set dayStr to item 1 of dayForcast
   set forcastStr to item 2 of dayForcast
   log "Day: " & dayStr
   log "Forcast: " & forcastStr
end repeat

Regards,
Matt

Posted on
Mon Feb 23, 2004 9:37 pm
gregjsmith offline
Posts: 946
Joined: Apr 01, 2003
Location: Rio Rancho, NM

(No subject)

Thanks Matt!

Here's the completed script for others that are interested.

--[url=applescript://com.apple.scripteditor/?action=new&script=tell%20application%20%22WeatherManX%22%0A%09set%20forcastList%20to%20Forecast%0Aend%20tell%0Atell%20application%20%22Indigo%22%0A%09repeat%20with%20dayForcast%20in%20forcastList%0A%09%09set%20dayStr%20to%20item%201%20of%20dayForcast%0A%09%09set%20forcastStr%20to%20item%202%20of%20dayForcast%0A%09%09log%20%22Day%3A%20%22%20%26%20dayStr%0A%09%09log%20%22Forcast%3A%20%22%20%26%20forcastStr%0A%09end%20repeat%0Aend%20tell%0A]Click here to open this script in a new Script Editor window[/url].

tell application "WeatherManX"
     set forcastList to Forecast
end tell
tell application "Indigo"
     repeat with dayForcast in forcastList
          set dayStr to item 1 of dayForcast
          set forcastStr to item 2 of dayForcast
          log "Day: " & dayStr
          log "Forcast: " & forcastStr
     end repeat
end tell


Now to do something useful with it.

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 35 guests