Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MrLDarragh

macrumors newbie
Original poster
May 3, 2010
5
0
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:
 
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.
 
Thanks

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.

Thanks but didn't work:(
 
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
 
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


This works, but it is not giving me the weather where I live. How do I change this?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.