I'm new to AppleScript but learned a bit from searching online. Basically I would like to forward iMessage messages to an e-mail address. I did this with the following script:
using terms from application "Messages"
on message received theMessage from theBuddy for theChat
tell application "Mail"
set theNewMessage to make new outgoing message with properties {subject:"thesubject", content:theMessage, visible:true}
tell theNewMessage
make new to recipient at end of to recipients with properties {address:"myemail@gmail.com"}
send
end tell
end tell
end message received
end using terms from
Works great and it puts the iMessage in the content of an e-mail that gets sent to me.
Now I'm trying to do this with attachments as well. I modified the code to give me 4 beeps when a file is received but nothing happens. Posted this question to Apple's website but then I thought I would have better luck here. Any help would really be appreciated I've searched google for hours and I'm kind of at a dead end.
Modified Code:
using terms from application "Messages"
on message received theMessage from theBuddy for theChat
tell application "Mail"
set theNewMessage to make new outgoing message with properties
{subject:"thesubject", content:theMessage, visible:true}
tell theNewMessage
make new to recipient at end of to recipients with properties
{address:"myemail@gmail.com"}
send
end tell
end tell
end message received
on completed file transfer theFile
beep 4
end completed file transfer
end using terms from
So with a bit more looking I learned that Messages is very similar to iChat which I found some example code on Apple's Developer site: https://developer.apple.com/library/mac/#samplecode/iChatAppleScriptSamples/Listings/Add_Incoming_Images_to_iPhoto_Add_incoming_image_to_iPhoto_applescript.html
So I changed my code to this:
on received file transfer invitation theFileTransfer
accept transfer of theFileTransfer
tell application "Mail"
set theNewMessage to make new outgoing message with properties
{subject:"photo", content:"themessage", visible:true}
tell theNewMessage
make new to recipient at end of to recipients with properties
{address:"myemail@gmail.com"}
send
end tell
end tell
end received file transfer invitation
I also made sure to have the script run when incoming file in the Messages preferences window, but still not getting any response. Very frustrating, I'm thinking that a picture might not be a file transfer but rather an inline text attachment of sorts.
Looking at the Messages dictionary I found:
attachment n [inh. rich text] : Represents an inline text attachment. This class is used mainly for make commands. elements contained by rich text, characters, paragraphs, words, attribute runs. properties file (file, r/o) : The path to the file for the attachment syn file name
But I have no idea how to use classes in AppleScript. Again any help would be greatly appreciated!