View unanswered posts | View active topics It is currently Thu May 23, 2013 4:25 am



Reply to topic  [ 3 posts ] 
 Some Text Editing Help? 
Author Message

Joined: Nov 26, 2009
Posts: 925
Location: Kalispell, MT
Post Some Text Editing Help?
Hey,

Always get stuck on something in Applescript land.

What's happening is I display a weather icon for tomorrows forecast based on info I download
from a weather site. The info they supply is always changing for some reason. One day it might
be, "Fog and Rain", then later, "Rain with Fog" making it cumbersome to use setting up variables.

In plugging along with this, I got it worked out to convert a "Fog and Rain", or "Rain and Fog"
to what I need.
The problem now is how to limit one like, "Some Rain" to not be triggered by the above, "Fog and Rain" and only
trigger when just "Rain" is present.

Essentialy looking for some code like this: if the theText contains ONLY the keepThis then

Really appreciate the help, someday I'll get a handle on this.

Thanks again,

Carl

Here's the general idea:

Code: Select all
tell application "IndigoServer"
   set theText to value of variable "Weather_Condition"
   set keepThis1 to "Cloudy" as string
   set keepThis2 to "Fair" as string
   set keepThis3 to "Mist" as string
   set keepThis4 to "Fog" as string
   set keepThis5 to "Freezing" as string
   set keepThis6 to "Hail" as string
   if the theText contains the keepThis1 then
      set the value of variable "Weather_Condition" to "Cloudy"
   end if
   if the theText contains the keepThis2 then
      set the value of variable "Weather_Condition" to "Fair"
   end if
   if the theText contains the keepThis3 and theText contains the keepThis4 then
      set the value of variable "Weather_Condition" to "Fog_Mist"
   end if
   if the theText contains the keepThis4  the keepThis3 then
      set the value of variable "Weather_Condition" to "Fog"
   end if


Fri Aug 03, 2012 2:52 pm
Profile
Site Admin
User avatar

Joined: Mar 19, 2008
Posts: 6659
Location: Austin, Texas
Post Re: Some Text Editing Help?
Your script above is almost right - you just missed a couple of things. You also had lots of extra "the"s which I removed since they aren't necessary and made reading the script a little confusing. Also, in order to keep the script from continuing on through the if statements after it had already found a match, I changed each consecutive "if" to an "else if" - so either 0 or 1 of the if statements will fire and nothing else. I personally wouldn't make clearly readable strings like "Cloudy" and "Fog" into unreadable variables (keepThis*) - just use the string.

The problem now is how to limit one like, "Some Rain" to not be triggered by the above, "Fog and Rain" and only
trigger when just "Rain" is present.


I think your 3rd "if" is close. I think this, for instance, would work in that particular scenario (it's the last else if):

Code: Select all
tell application "IndigoServer"
   set theText to value of variable "Weather_Condition"
   if theText contains "Cloudy" then
      set the value of variable "Weather_Condition" to "Cloudy"
   else if theText contains "Fair" then
      set the value of variable "Weather_Condition" to "Fair"
   else if theText contains "Mist" and theText contains "Fog" then
      set the value of variable "Weather_Condition" to "Fog_Mist"
   else if theText contains "Fog" then
      set the value of variable "Weather_Condition" to "Fog"
   else if theText contains "Rain" and theText contains "Fog" then
      set the value of variable "Weather_Condition" to "Fog_Rain"
   end if
end tell

_________________
Jay (Indigo Support)
Image


Fri Aug 03, 2012 4:25 pm
Profile WWW

Joined: Nov 26, 2009
Posts: 925
Location: Kalispell, MT
Post Re: Some Text Editing Help?
Perfect, as always. Thanks to your help I'm able to can about 30 triggers.


Carl


Fri Aug 03, 2012 9:38 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.   Template designed by STSoftware.