Hacker News new | ask | show | jobs
by anonymouse008 833 days ago
Here's an Apple Script moving through iMessage to SMS if required. Make sure to add helpers to update the recipients contact to default to SMS, otherwise you're just cluttering your Messages history with failed messages.

--------

tell application "Messages" set phoneNumber to "+15555555555" set messageToSend to "This is a test!"

try set iMessageService to (1st account whose service type = iMessage) set iMessageBuddy to participant phoneNumber of iMessageService

  if exists iMessageBuddy then
   set theMessage to send messageToSend to iMessageBuddy
   delay 2 -- Wait for a short time to allow the message status to update
   
   if status of theMessage is not "delivered" then
    error "iMessage not delivered"
   else
    log ("sent as iMessage to: " & phoneNumber)
   end if
  else
   error "Not an iMessage user"
  end if
 on error
  try
   set SMSService to (1st account whose service type = SMS)
   set SMSBuddy to participant phoneNumber of SMSService
   send messageToSend to SMSBuddy
   log ("sent as SMS to: " & phoneNumber)
  on error
   log ("ERROR: COULD NOT SEND TO: " & phoneNumber)
  end try
 end try
end tell
1 comments

Awesome!!!! Thank you