- Code: Select all
set targetMessage to "Some message to some target iMessage user"
tell application "Messages"
set targetService to 1st service whose service type = iMessage
set targetBuddy to buddy "INSERTIDHERE" of targetService # see discussion below for what identifier to use
send targetMessage to targetBuddy
end tell
The real trick is figuring out how to identify the buddy. Sometimes, the account you want to send to is identified by their phone number, including the + at the beginning: "+19875551234" or whatever. Other times, it's registered with their email address: "someemail@somehost.com" or whatever. The best way to see is to run the following script :
- Code: Select all
tell application "Messages"
buddies of (1st service whose service type = iMessage)
end tell
This will return a list of all the accounts that can receive iMessages. The buddies will look something like this:
buddy id "86ABE32D-7CCF-4116-BD3D-0C49F84932FA:someemail@somehost.com" of application "Messages"
or
buddy id "86ABE32D-7CCF-4116-BD3D-0C49F84932FA:+15055551234" of application "Messages"
The bolded part is what you want to use in the script above to identify the buddy.