Automator and AppleScript to automate messages

I am trying to create a script to send personal messages to some community members. I have excel file with Name and Phone number. I like to automate / create a script to,open file, read name and number and send message like - Hello <Name>, Thanks for supporting the community. Your ABC


I know that you can create AppleScript like


tell application "Messages"

send "Hello This is text" to buddy 456-454-4444 of service "SMS"

end tell


I am not able to automate with file read, pass parameters and loop it.

Posted on Dec 2, 2020 4:59 PM

Reply

Similar questions

4 replies

Dec 10, 2020 11:31 AM in response to MikeGToronto

This is pretty easy to do. You already have the code for sending the message, it's just a matter of substituting the name.


There are many ways to do that - some simpler than others. You might prefer to have the script read from Excel directly, or you might prefer to export the data as a comma-delimited text file and have AppleScript read that - lots of options.


Then just break your script down into critical parts - in this case one part to extract the data from excel/file/wherever; one to send the message; and a control loop.


You might end up with something like this (untested):


on get_member(id)
	tell application "Microsoft Excel"
		-- assumes column 1 for the name and column 2 for the phone number
		set _name to value of cell ("A" & id)
		set _number to value of cell ("B" & id)
		
		return {name:_name, number:_number}
	end tell
end get_member


on send_message_to(member)
	
	tell application "Messages"
		try
			send "Hello, " & name of member & ", This is text" to participant (number of member) of account "SMS"
		end try
	end tell
	
end send_message_to


set i to 2
repeat
	-- go get the data for the member
	set _member to get_member(i)
	if name of _member = "" then
		-- break on the first empty/missing name
		exit repeat
	end if
	
	send_message_to(_member)
	-- increment the counter
	set i to i + 1
end repeat


This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Automator and AppleScript to automate messages

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.