Applescript Weather

Discussion in 'Mac Programming' started by MrLDarragh, May 3, 2010.

  1. MrLDarragh macrumors newbie

    Joined:
    May 3, 2010
    #1
    Hello, I would like to write an applescript that reads out the weather when requested, Im quite new to applescript but can do lots! Can you post some examples for something that reads out weather! :confused:
     
  2. calderone macrumors 68040

    calderone

    Joined:
    Aug 28, 2009
    Location:
    Seattle
    #2
    Shell script would be a better option. Chances are you would turn to shell in AppleScript anyhow, so why not just use shell?

    You can however, combine shell with AppleScript. Here is an example:

    Shell script to grab current conditions

    Code:
    #!/bin/bash
    
    curl "http://weather.yahooapis.com/forecastrss?p=USIL0113&u=f" | grep -E '(Current Conditions:|F<BR)' | sed -e 's/Current Conditions://' -e 's/<br \/>//' -e 's/<b>//' -e 's/<\/b>//' -e 's/<BR \/>//' -e 's/<description>//' -e 's/<\/description>//'
    AppleScript that calls the shell script and using say to speak the conditions using the Fred voice

    Code:
    set currentConditions to do shell script "~/bin/custom/weather/scripts/conditions.sh"
    
    say currentConditions using "Fred"
    The reason for calling a separate shell script is because escaping all of that in AppleScript is a pain.
     
  3. MrLDarragh thread starter macrumors newbie

    Joined:
    May 3, 2010
    #3
    Thanks

    Thanks but didn't work:(
     
  4. mysterytramp macrumors 65816

    mysterytramp

    Joined:
    Jul 17, 2008
    Location:
    Maryland
    #4
    Try this, best of both worlds:

    Code:
    set weather to "curl " & quote & "http://weather.yahooapis.com/forecastrss?p=USIL0113&u=f" & quote
    
    set postWeather to "grep -E '(Current Conditions:|F<BR)'"
    
    set forecast to do shell script weather & " | " & postWeather
    
    (characters 1 through -7 of paragraph 2 of forecast) as string
     
  5. MrLDarragh thread starter macrumors newbie

    Joined:
    May 3, 2010
    #5
    Thanks

    Thanks guys,did it now it works as an alarm clock! :p
     
  6. calderone macrumors 68040

    calderone

    Joined:
    Aug 28, 2009
    Location:
    Seattle
    #6
    Thanks for the above.
     
  7. TylerMullins macrumors newbie

    Joined:
    Apr 11, 2013
    #7

    This works, but it is not giving me the weather where I live. How do I change this?
     
  8. ytk macrumors regular

    Joined:
    Jul 8, 2010
  9. Ap0ks macrumors 6502

    Joined:
    Aug 12, 2008
    Location:
    Cambridge, UK
    #9
    Made me chuckle :D

    Tyler, the documentation you need is here -> Yahoo Weather API, basically you need to alter the URL parameters used in the script to match the town you're after.
     

Share This Page