cyerye said:
Thanks evanlifetv - Could you share some of your examples? I'm using an iMac to run HaikuHelper and I use two airport expresses and a receiver with airplay to play music in house through iTunes. Using HaikuHelper to make announcements would eliminate my need for the 2 way voice module and the two microphone / speakers from HAI.
Sure thing, a little background:
From PcAccess, I have a flag that resets at 2pm each day, and then an action that basically determines using this flag if its my first time home after 5:00, if that makes sense, it also turns some lights on, lights the fireplace if its cold outside and of course trips the flag for me and activates a button called "Evening Update" (pretty straight forward HAI programming)
At the same time as all of that stuff, Haiku does a simple 'If Zone trips Not Ready' Then I use this:
function onButtonActivate(button) {
if(button.name == 'Forecast') {
helper.executeAppleScript(controller, 'tell application "evening_update" to activate');
}
}
'evening_update' is just an applescript application containing the following:
--this is the city code. Search the code for your city on http://weather.yahoo.com/
set CityCode to 11111111
--temperature format
set t_format to "F"
--voiceover format
set v_format to "L"
--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
--Get current time and make it speakable
set myhour to get the (hours of (current date)) as string
set myminutes to get the (minutes of (current date)) as string
-- add a leading zero to minutes
set minuteslength to (length of myminutes)
if minuteslength < 2 then
set myminutes to "0" & myminutes
end if
-- say the time
-- the colon makes it say, eg, 20 : 45 instead of 2 thousand 45
set volume output volume 100
tell application "iTunes"
set the sound volume to 75
end tell
-- Announce Time of Day
say "The time is " & myhour & ":" & myminutes using "Serena"
delay 1
--says the weather
say "Just an update. The weather currently is " & actual_temp using "Serena"
-- say "The remainder of the day is" & today_forecast using "Serena"
delay 1
say "Tomorrows Forcast is" & tomorrow_forecast using "serena"
delay 1
say "Your Remaining Reminders are:" using "Serena"
--says notes
say (do shell script "cat '" & "/Users/username/Desktop/Notes.txt" & "'") using "Serena"
tell application "iTunes"
set the sound volume to 100
end tell
Most of that code was adapted or tweaked from the now 'retired' (I believe) ProjectJarvis... There are others out there like it to get ideas.
I also have a button called "Romance" that when pushed dims all my lights, turns on the fireplace, and fires off an iTunes playlist with some nice tunes.
You can do this type of stuff a dozen ways, just pick the way you are most comfortable with and start typing, I could probably do all of this from within Haiku, but I already had the HAI stuff programmed before I started messing with Haiku, so I just left those in there.
Here are something that might help as you start the applescript journey, with airplay:
http://dougscripts.com/itunes/ (basic iTunes scripting)
http://rogueamoeba.com/airfoil/mac/ (allow system audio via airplay)
Let me know if you have any specific questions, I'll help out where I can!