I'm hoping someone can help me clean this up and improve upon it.
This is my first post here, and my first dabbling with AppleScript today (or much of any programming for that matter). I see this issue of sending out SMS alerts come up from time to time. 6 Months ago I set up Adium to start exploring this (looked at SMS Mac and for some reason wasn't satisfied at the time) but never got back around to it. As I recall, the AIM SMS gateway via Adium is free, and fairly easy to setup (at least for US users). I had some streak of stubbornness today, and stuck with this until it worked.
What I wanted was a way to integrate Adium SMS messages with some Indigo variables, and fire up and shutdown Adium so that it wasn't running all the time in the background. Using Indigo, I wanted to set the account name, message contents, and message destination by changing variables in Indigo through triggers.
Here is what I have - using 3 Indigo variables. I've tried to make this easily reusable and extensible, but I'm sure I've done some things in a really convoluted way. If you can offer improvements, I'd welcome them.
- Code: Select all
--------------------------------------------------------------------------------------------------------------
-- SMS via Adium Script
--
-- JBB (03/31/2009)- Initial script
--------------------------------------------------------------------------------------------------------------
-- Define the right hand side of the following pairs as Indigo Variables
-- -- Use Indigo variables in triggers to set receiving phone no. (SMSDest), and Message (SMSMsg)
-- -- Set the following property to be the SMSMsg Variable
--
property theMessage : "SMSMsg"
--
-- Set the following property to be the SMSDest Variable
--
property theDest : "SMSDest"
--
-- Set the following property to be the Adium Account Display Name (Displayed on Contacts Page)
property theAdiumAcct : "AdiumAcct"
--
--------------------------------------------------------------------------------------------------------------
-- Don't change anything below this unless you're sure you know what you're doing
--------------------------------------------------------------------------------------------------------------
--
-- First process both variables to populate them in script from Indigo Variables
--
processVariable(theMessage)
processVariable(theDest)
on processVariable(theInputVariable)
tell application "IndigoServer"
local theVarValue -- useful for debugging with ScriptDebugger but not needed
local theVarValueName -- useful for debugging with ScriptDebugger but not needed
-- most of this section unnecessary - comment out log line to reduce log pollution
set theVarValue to value of variable theInputVariable as string
set theVarValueName to name of variable theInputVariable as string
log "Attempting to send SMS Message with variable " & theVarValueName & " set to " & theVarValue
end tell
end processVariable
tell application "Adium"
activate
go online
delay 5
tell service "AIM"
--
-- Seems to be no way to reference Adium Accts by Display Name
-- -- Instead, iterate through all accounts and send message with each acct that
-- -- matches display name. Hope you do not have duplicate display names!
--
set listOfAccts to every account
repeat with theCurrentValue in listOfAccts
tell theCurrentValue
if display name of theCurrentValue contains theAdiumAcct then
make new chat with contacts {contact theDest} with new chat window
send the active chat message theMessage
end if
end tell
end repeat
end tell
delay 2
close active chat
go offline
close
quit
end tell
-- optional Growl integration
-- tell application "GrowlHelperApp"
-- set the allNotificationsList to {"SMS Sent via Adium"}
-- set the enabledNotificationsList to {"SMS Sent via Adium"}
-- register as application "SMS via Indigo Adium AppleScript" all notifications allNotificationsList default notifications enabledNotificationsList icon of application "Script Editor"
-- notify with name "SMS Sent via Adium" title "SMS Sent" description theMessage application name "SMS via Indigo Adium AppleScript"
-- end tell
tell application "IndigoServer"
log "SMS Message Sent, **" & value of variable theMessage & "** to: " & value of variable theDest
end tell