I have an email<–>SMS gateway provider that accepts SMSs in the form phonenumber@their.domain.com.au, so I have written an AppleScript address book plugin to set up an email to send an SMS to any given phone number.
This is the script I have currently:
using terms from application "Address Book"
on action property
return "phone"
end action property
on action title for aPerson with aPhone
return "SMS With MessageNet"
end action title
on should enable action for aPerson with aPhone
return true
end should enable action
on perform action for aPerson with aPhone
set fullName to (name of aPerson as string)
set telephone to ""
if value of aPhone is not missing value then set telephone to value of aPhone
-- TODO Remove any non-number characters from the string
-- Hack for now: Remove spaces
set AppleScript's text item delimiters to " "
set telephone to telephone's text items
set AppleScript's text item delimiters to ""
set telephone to "" & telephone
set AppleScript's text item delimiters to {""}
set emailAddress to telephone & "@messagenet.com.au"
tell application "Mail"
set newMessage to make new outgoing message with properties {subject:"", content:""}
tell newMessage
make new to recipient at end of to recipients with properties {address:emailAddress, name:fullName}
set visible to true
end tell
activate
end tell
end perform action
end using terms from
It works perfectly except that the gateway wants the SMS in the email body and Mail.app defaults to leaving the focus in the email subject which is ignored. This is not a huge problem, except that it’s bugging me that I can’t figure out how to fix it - I tried putting four “keystroke tab” lines after the “activate” line to move the focus, with and without various delays, but they don’t seem to DO anything and I can’t figure out why…
Also, would anybody have the slightest idea why this script works in Leopard but not Tiger? I couldn’t get it to set the recipient properly previously, but once I installed Leopard it worked right away. Weirdness.
Thanks in advance,
Ricky