Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MACza

macrumors member
Original poster
May 10, 2011
56
0
Hi Guys!

I hope somebody can assist me with an applescript I am attempting.

The aim: to send myself an image from my MAC to my iphone via Messages/iMessage.

OK, I can send text messages successfully with the following:

Code:
tell application "Messages"
	set myid to get id of first service
	set theBuddy to buddy "+123456789" of service id myid
	send "Test message" to theBuddy
end tell

How do I now add an image to the message?

I was trying something like the following:

Code:
tell application "Messages"
	set myid to get id of first service
	set theBuddy to buddy "+123456789" of service id myid
	set targetFileName to "Macintosh HD:Users:user:Pictures:picture.PNG:"
	make new attachment with properties {file:targetFileName}
	send "Test message" to theBuddy
end tell

WIth the above, I get the following error back:
"Messages got an error: Can’t make or move that element into that container."

I am not sure what this means or what the solution is :confused:

It also seems like I should tell Messages to send the attachment. Not sure if it should be part of the "send" command, or if I should send the image in it's own "send" call.

Any help will be greatly appreciated! :D

Thanks!
 

keithjmason

macrumors newbie
Nov 8, 2012
1
0
Hi,

Would you mind sharing how you sorted this out ? Trying to do the same thing.

Thanks!

Keith
 

dhval

macrumors newbie
Jan 30, 2013
1
0
set theAttachment1 to POSIX file /Users/lil/pic.png
tell application "Messages"
send theAttachment1 to buddy "+1 (xxx) x7 " of service "E:yourappleid@gmail.com"
end tell
 

Jaccobk

macrumors newbie
May 31, 2016
1
0
When you are setting attachments you need to have your file enclosed in quotes

set ttheAttachment1 to POSIX file "/Users/Andrew/Desktop/EnergyUse.pdf"

This is an example of sending a PDF not just a picture. The POSIX was a true help thanks dhval
 

Nest

macrumors newbie
Sep 20, 2017
1
0
Hello
I am a beginner in this field and I am not good at English.
I tried to listen to a lot of advice above, but it failed repeatedly.
This shell will help if someone is in the same situation as me.

tell application "Messages"

set targetBuddy to "abc@def.com"

set targetService to id of 1st service whose service type = iMessage

set textMessage to POSIX file "/Users/nest/Desktop/test.txt"

set theBuddy to buddy targetBuddy of service id targetService

send textMessage to theBuddy

end tell

I made it and it succeeded.
Even if it's a mess, please understand. TT
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.