by anonymouse008 · 2y ago · 0 comments
--------
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