How to create new message in iChat without sending, using Automator to grab selected text

applescriptichatmessages

I am trying to create a service that grabs the URL of some link, then create a blank iMessage with that URL in the body. Basically, I want to recreate that Message share feature in Safari in Mountain Lion, but with Reeder.app, specifically. "Copy Link" from the context menu doesn't always work, esp. when sending to a iphone, the URL drops, and all you get is the alias.

I've set up an Automator with Applescript, and I can definitely send a message to a buddy, if those things are specified. I'd prefer to populate that in iMessage, since I won't always be sending to the same person.

Below works, using set input as a proxy for automator's url grabbing at the moment.

set input to "http://aol.com"
tell application "Messages"
          set theBuddy to buddy "camelot@mac.com" of service "iCloud"
          send input to theBuddy
end tell

Also tried

tell application "Messages"
    set theBuddy to buddy "*" of service "iCloud"
    set input to invitation message of text chat of service "iCloud"
end tell

Both from https://discussions.apple.com/thread/3923965?start=0&tstart=0

Best Answer

You have to do it with UI scripting :

tell application "System Events" to tell process "Messages"
    set input to "http://aol.com" as text
    click button 1 of group 1 of splitter group 1 of window 1
    delay 1
    keystroke "Buddy@provider.com" -- type the reciever
    keystroke return -- validate the previous input
    keystroke tab -- move to message input
    keystroke input -- type the message
end tell