Messages - send to multiple recipients

I would like to send an iMessage to multiple recipients from Messages, don’t know how to adjust the code I have for sending to a single recipient:

tell application "Messages"
	send "test message" to buddy "0709123456" of service "E:user@domain.com"
end tell

I know I can use this, but I want to have one single specified content and multiple buddies/recipients.

tell application "Messages"
	send "test message" to buddy "0709123456" of service "E:user@domain.com"
	send "test message" to buddy "0709987654" of service "E:user@domain.com"
end tell

Anyone?

Hi,

there is no command in Messages to send one message to a group of buddies.
A repeat loop can do it


property buddyList : {"0709123456", "0709987654"}

repeat with aBuddy in buddyList
	tell application "Messages"
		send "test message" to buddy aBuddy of service "E:user@domain.com"
	end tell
end repeat

Hi Stefan, and as usual, thanks!

What would be better is to be able to send to a group of buddies, which is something you could do manually (or with UI scripting). The difference is that one iMessage (to a group or multiple buddies/recipients) represents only one row in Messages which is better sometimes.

So there’s no equivalent to this UI script, right?:

delay 0.2
tell application "Messages"
	activate
end tell

delay 0.5

tell application "System Events"
	keystroke "n" using {command down}
	delay 0.8
	-- 1st buddy:
	keystroke "0709123456"
	delay 0.5
	keystroke return
	delay 0.1
	-- 2nd buddy:
	keystroke "0709987654"
	delay 0.5
	keystroke return
	delay 0.1
	-- send message:
	keystroke tab
	delay 0.1
	keystroke tab
	keystroke "test message"
	keystroke return
end tell

So the two alternatives for me is your script above Stefan, and the UI one here.
Could it be that non-UI scripts are somewhat more stable?
Could there be another disadvantage to the UI script alternative?

EDIT: It seems one disadvantage is that if one buddy in the group isn’t connected to iMessage, then the iMessage won’t be sent at all.

is there any update on this thread for 2015? as a group message.

alternative to UI

Hey slashdot,


set targetBuddyHandle to “myHandle@someDomain.com

tell application “Messages”
if not running then run
activate

set thisBuddy to first buddy whose handle is targetBuddyHandle and service type of service of it is iMessage
set thisChat to make new text chat with properties {participants:{thisBuddy}}

# set thisMessage to send "I am nuts!" to thisChat

end tell

Note that participants is a list, so yes you can send to multiple people.

-Chris


MacBookPro6,1 · 2.66 GHz Intel Core i7 · 8GB RAM · OSX 10.10.4

Ran this code

set targetBuddyHandle to "myappleidEmail@gmail.com"

set participants to {"buddy1", "buddy2"}

tell application "Messages"
	if not running then run
	activate
	
	set thisBuddy to first buddy whose handle is targetBuddyHandle and service type of service of it is iMessage
	set thisChat to make new text chat with properties {participants:{thisBuddy}}
	
	
	set thisMessage to send "test" to thisChat
	
end tell

got this error:

It seems that you didn’t understood correctly the proposal.

My understanding is that you were asked to code :

set targetBuddyHandle to "myappleidEmail@gmail.com"

tell application "Messages"
	if not running then run
	activate
	
	set thisBuddy to first buddy whose handle is targetBuddyHandle and service type of service of it is iMessage
	set thisChat to make new text chat with properties {participants:{"buddy1", "buddy2"}}
	
	
	set thisMessage to send "test" to thisChat
	
end tell

But, CAUTION,
(1) myappleidEmail@gmail.com must be replace by a valid, existing address
(2) “buddy1” and “buddy2” must be replaced by true, existing names of correspondants.

Yvan KOENIG running Yosemite 10.10.4 in French (VALLAURIS, France) lundi 10 août 2015 18:57:17

Thanks for the clarification and the updated code.

I’ve took account and adopted your cautions. However, still get an error.

Question: When you run the code above does it work for you?

I don(t use Messages so none of the predefined values aren’t defined on my machine.

I just pointed your visible oddities hoping that after defining correctly the required values the script would work.

Yvan KOENIG running Yosemite 10.10.4 in French (VALLAURIS, France) lundi 10 août 2015 21:27:08

Thanks for the update.

So

set targetBuddyHandle to "valid-messagesaccount@account.com"

results in the following error:

or

set targetBuddyHandle to "+15551212"
set thisChat to make new text chat with properties {participants:{"valid1@mail.net", "valid2@mail.net"}}

results:

bump for an alternative to UI scripting.

thanks