In 2023, are there still reliability issues with sending iMessages via AppleScript?
ie:
Warning: there have been cases where Messages sends the message to the wrong recipient. Do not send overly sensitive messages and verify delivery.
Via: actions:Send Message [Keyboard Maestro Wiki]
In my quick test (Monterey 12.6
, KM 10.2
), I found that the following (via Chris Pennington – Send iMessage With AppleScript) seems to work reliably:
on run argv
tell application "Messages"
set targetBuddy to "(XXX) XXX-XXXX"
set targetService to id of 1st account whose service type = iMessage
set textMessage to ( item 1 of argv )
set theBuddy to participant targetBuddy of account id targetService
send textMessage to theBuddy
end tell
log "Message sent"
end run
I wonder:
- Is this fundimentally the same as what Keyboard Maestro is using to pass information to
Messages.app
? - It would seem that targeting the
Phone Number
orEmail Address
of a contact would have less chance of sending to thewrong recipient
. But I don't know why this "bug" occurs.
I see that the Messages Suite
(in Script Editor.app
) has a few ways to target what should be a unique ID:
participant n : A participant for an account. syn buddy
elements
contained by application, accounts, chats.
properties
id (text, r/o) : The participant's unique identifier. For example: 01234567-89AB-CDEF-0123-456789ABCDEF:+11234567890
account (account, r/o) : The account for this participant.
name (text, r/o) : The participant's name as it appears in the participant list.
handle (text, r/o) : The participant's handle.
first name (text, r/o) : The first name from this participan's Contacts card, if available
last name (text, r/o) : The last name from this participant's Contacts card, if available
full name (text, r/o) : The full name from this participant's Contacts card, if available
But again, because I don't know what the fundamental issue is, maybe all of these methods are affected and unreliable.
Thanks.
Related threads: