SOLVED!
Somehow I took my variables weather_loc and weather_ac outside of the AIOControls parser, where they are called. What’s weird is even though I declared them globaly they still had to be inside of the parser? I think maybe the reason I had them outside is because when I release the final version I wanted the only part of the code that needed to be edited at the very top. So an ease of use sort of deal. Dropping them 1 line into the parser isn’t that far of a drop so i can deal. Edited the code below to reflect the fix. I think in the future I will create a settings file? Maybe? that’s just more crap adding unnecessary size and bulk to the script. Who knows though.
Now that is fixed is there anything the community would like to see in an iChat automation script that I don’t have currently coded in? I know there are a lot of things I want to add, but they would only reflect my system. So I am going to make one big ol script and release it and then mod it to meet my needs later
++Old post begins++
I had this working perfectly and honestly have spent the last hour or better going over my script trying to figure out what happened. I even rewrote the pissing then hoping I would find what I was looking for…
Using the iTunes Remote Control from iChat as a jumping board I wanted to create something that would be comparable to TweetMyMac but instead use AIM so as to bypass Twitter and job place restrictions.
using terms from application "iChat"
on AIOControls(theMessage)
set weather_loc to "~/Desktop/weather.py"
global weather_loc
set weather_ac to "48413"
global weather_ac
set theResponse to "Invalid command."
if theMessage is "status" then
set theResponse to getCurrentiTunesTrack()
else if theMessage is "next" then
tell application "iTunes"
next track
end tell
set theResponse to "Playing next track. " & getCurrentiTunesTrack()
else if theMessage is "previous" then
tell application "iTunes"
previous track
end tell
set theResponse to "Playing previous track. " & getCurrentiTunesTrack()
else if theMessage is "mute" then
tell application "iTunes"
set mute to true
end tell
set theResponse to "iTunes muted. " & getCurrentiTunesTrack()
else if theMessage is "unmute" then
tell application "iTunes"
set mute to false
end tell
set theResponse to "iTunes unmuted. " & getCurrentiTunesTrack()
else if theMessage is "play" then
tell application "iTunes"
play
end tell
set theResponse to getCurrentiTunesTrack()
else if theMessage is "pause" then
tell application "iTunes"
pause
end tell
set theResponse to getCurrentiTunesTrack()
else if theMessage is "time" then
set theTime to time string of (current date)
set theResponse to "The current time is " & theTime
else if theMessage is "volume up" then
set out_vol to output volume of (get volume settings)
if out_vol = 100 then
set theResponse to "Volume is currently maxed."
else
set volume output volume (out_vol + 10)
if (out_vol + 10) > 100 then
set theResponse to "Volume raised to 100%"
else
set theResponse to "Volume raised to " & (out_vol + 10) & "%"
end if
end if
else if theMessage is "volume down" then
set out_vol to output volume of (get volume settings)
if out_vol = 0 then
set theResponse to "Volume is currently muted."
else
set volume output volume (out_vol - 10)
if (out_vol - 10) < 0 then
set theResponse to "Volume lowered to 0%"
else
set theResponse to "Volume lowered to " & (out_vol - 10) & "%"
end if
end if
else if theMessage is "volume" then
set out_vol to output volume of (get volume settings)
set theResponse to "The volume is currently set at " & out_vol & "%."
else if theMessage is "volume max" then
set volume output volume (100)
set theResponse to "Volume maxed!"
else if theMessage is "volume mute" then
set volume output volume (0)
set theResponse to "Volume muted!"
else if theMessage is "current weather" then
set the_weather to do shell script ("python " & weather_loc & " " & weather_ac)
set theResponse to the_weather
else if theMessage is "current conditions" then
set the_weather to do shell script ("python " & weather_loc & " -c " & weather_ac)
set theResponse to the_weather
else if theMessage is "current temperature" then
set the_weather to do shell script ("python " & weather_loc & " -t " & weather_ac)
set theResponse to the_weather
else if theMessage is "forecast today" then
set the_weather to do shell script ("python " & weather_loc & " -f1 " & weather_ac)
set theResponse to the_weather
else if theMessage is "forecast 2 day" then
set the_weather to do shell script ("python " & weather_loc & " -f2 " & weather_ac)
set theResponse to the_weather
else if theMessage is "help" then -- Displays availible commands
set theResponse to "Aaon's AIO iChat Controller v1.0 rev2
Availible commands:
help - Returns this list
time - Returns current time
volume - Returns current volume
volume up - Increases volume
volume down - Decreases volume
volume max - Sets volume to 100%
volume mute - Sets volume to 0%
current weather - Returns current weather **Configure in script**
current conditions - Returns current conditions only
current temperature - Returns current temperature only
forecast today - Returns todays forecast
forecast 2 day - Returns today and tommorrows forecast
iTunes specific commands:
status - Returns current track
next - Plays next track
previous - Plays previous track
mute - Mutes iTunes
unmute - Unmutes iTunes
play - Tells iTunes to start playing
pause - Tells iTunes to stop playing"
end if
end AIOControls
on message received theMessage from theBuddy for theChat
-- run the AIO parser.
set theResponse to AIOControls(theMessage)
-- send back the response.
send theResponse to theChat
end message received
on getCurrentiTunesTrack()
set theCurrentTrackMessage to "Not playing."
tell application "iTunes"
if player state is playing then
set theCurrentTrackMessage to "Now playing \"" & (name of current track) & "\""
if (artist of the current track) is not missing value then
set theCurrentTrackMessage to theCurrentTrackMessage & " by " & (artist of the current track)
end if
if mute then
set theCurrentTrackMessage to theCurrentTrackMessage & " (muted)"
end if
end if
end tell
return theCurrentTrackMessage
end getCurrentiTunesTrack
-- Run Script Editor to test.
display dialog "Command to test:" default answer "help"
set theMessage to the text returned of the result
set theResponse to AIOControls(theMessage)
display dialog theResponse
end using terms from
(*
Weather.py by Thomas Upton with contributions from Chris Lasher.
Licensed under a BY-NC-SA Creative Commons license.
*)
The problem I am having is with the weather. When I run the script in the editor and enter “current weather” it gives me the correct response. However, when I run it though iChat, or any of the other weather commands, the script jumps to the end Prompts me to enter a command, as it would if ran in the script editor. AND iChat tells me the variable weather_loc is not defined.
Like I said above I have gone as far as rewriting the code and it worked in the beginning.
The weather.py script can be found here: http://github.com/tupton/python-yahoo-weather