Programmatically send text message through Messages app on OS X 10.10

messagessms

With OSX 10.10 you can now send and receive text messages through your phone, from your mac. Is it possible to do this programatically? Either via applescript or a reverse engineered API?

Best Answer

Using:

tell application "Messages"
    get name of every service
end tell

I noticed that I have "SMS" as a 4th option (yours may be different). So then I used:

launch application "Messages"
tell application "Messages"
     activate --steal focus

     set targetBuddy to "12345550123"
     set targetService to id of service "SMS"
     set textMessage to "Just a test"

     set theBuddy to buddy targetBuddy of service id targetService
     send textMessage to theBuddy
end tell

This lets me send a text message over SMS Relay. I'm not 100% sure that I did this correctly, but it does work if targetService points to "SMS". Now to convert it to script that works from the terminal.