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

AnimalCrackers

macrumors newbie
Original poster
May 22, 2011
3
0
Hey guys,
I'm trying to set something up on my Mac. Ideally, I would like to tell my create my own voice-recognition command in which I say "Computer, Weather" and following that, a weather script I found turns on. This is the weather script.

--TellMeTheWeather Applescript v0.3e
--Federico Villa
--federico.villa@gmail.com
--http://www.infede.com
--2010-07-16

--this is the city code. Search the code for your city on http://weather.yahoo.com/
set CityCode to 718345
--temperature format
set t_format to "C"
--voiceover format
set v_format to "S"
--say present condition
set a_format to "Y"

set IURL to "http://weather.yahooapis.com/forecastrss?w=" & CityCode

--downloading the file using curl
set file_content to (do shell script "curl " & IURL)
--looking for the line with actual condition
set theText to text ((offset of "yweather:condition" in file_content) + 1) thru -1 of file_content
set sub_1 to text ((offset of "\"" in theText) + 1) thru -1 of theText

--today conditions found
set actual_condition to text 1 thru ((offset of "\"" in sub_1) - 1) of sub_1

--looking for actual temperature temperature
set sub_1a to text ((offset of "temp=" in sub_1)) thru -1 of sub_1
set sub_1b to text ((offset of "\"" in sub_1a) + 1) thru -1 of sub_1a
set actual_temp to text 1 thru ((offset of "\"" in sub_1b) - 1) of sub_1b

if t_format is equal to "C" then
set actual_temp to (5 / 9) * (actual_temp - 32) as integer
end if

--looking for today forecast
set theText to text ((offset of "yweather:forecast" in file_content) + 1) thru -1 of file_content
set sub_2 to text ((offset of "\"" in theText) + 1) thru -1 of theText

--maximum and minimum temperatures found
set today_min_temp to word 9 of sub_2
set today_max_temp to word 12 of sub_2
if t_format is equal to "C" then
set today_min_temp to (5 / 9) * (today_min_temp - 32) as integer
set today_max_temp to (5 / 9) * (today_max_temp - 32) as integer
end if

--looking for today forecast condition (a bit tricky)
set sub_3 to text ((offset of "text" in sub_2) + 1) thru -1 of sub_2
set sub_4 to text ((offset of "\"" in sub_3) + 1) thru -1 of sub_3
set today_forecast to text 1 thru ((offset of "\"" in sub_4) - 1) of sub_4

--looking for tomorrow forecast
set sub_5 to text ((offset of "yweather:forecast" in sub_4) + 1) thru -1 of sub_4
set sub_6 to text ((offset of "\"" in sub_5) + 1) thru -1 of sub_5

--maximum and minimum temperatures found
set tomorrow_min_temp to word 9 of sub_6
set tomorrow_max_temp to word 12 of sub_6
if t_format is equal to "C" then
set tomorrow_min_temp to (5 / 9) * (tomorrow_min_temp - 32) as integer
set tomorrow_max_temp to (5 / 9) * (tomorrow_max_temp - 32) as integer
end if

--looking for tomorrow forecast condition (a bit tricky)
set sub_7 to text ((offset of "text" in sub_6) + 1) thru -1 of sub_6
set sub_8 to text ((offset of "\"" in sub_7) + 1) thru -1 of sub_7
set tomorrow_forecast to text 1 thru ((offset of "\"" in sub_8) - 1) of sub_8

--VoiceOver Section
if a_format is equal to "Y" then
say "Now, " & actual_condition & ", " & actual_temp & " degrees"
end if
if v_format is equal to "L" then
say "Today: " & today_forecast & ". Temperature: between " & today_min_temp & " and " & today_max_temp & " degrees. Tomorrow: " & tomorrow_forecast & ". Temperature: between " & today_min_temp & " and " & today_max_temp & " degrees" using "Vicki"
else
say "Today: " & today_forecast & ", between " & today_min_temp & " and " & today_max_temp & " degrees. Tomorrow: " & tomorrow_forecast & ", between " & tomorrow_min_temp & " and " & tomorrow_max_temp & " degrees" using "Vicki"
end if

Any help appreciated!
 
With the script open in your AppleScript Editor, choose File > Save As > File Format: script. Save the script to your Speakable Items Folder, located inside your Home > Library > Speech folder.

The name you choose for the saved script must correspond exactly to the spoken command you intend to use. For example, if you won't be using a keyword when speaking, save the script with the name "Computer Weather." If, however, you will be using the (default) "Computer" keyword, just name the script "Weather."

Make sure that Speakable Items is turned on in System Preferences > Speech > Speech Recognition.

The above is based on my test in Tiger; names and locations of named folders may vary in systems beyond Mac OS 10.4.11. I used your script as written, and it worked flawlessly the first time. Good luck.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.