AppleScript to send new iMessage

Hey guys - I'm trying to create an apple script to send a new iMessage. But I'm stuck. Can anybody help?


tell application "System Events"

tell application "Messages" to activate

tell process "Messages"

click menu item "New Message" of menu "file" of menu bar 1

end tell

...

endtell


... and thats it. How Do I tell Messages to fill in an email adress or phone number now and to send it?


Thank you!

Mac Pro (Early 2008), OS X Mountain Lion (10.8.2)

Posted on Sep 21, 2012 3:05 AM

Reply
Question marked as Top-ranking reply

Posted on Sep 21, 2012 8:18 PM

The best way is to not use UI Events at all - they're cumbersome at best. Instead consider the direct approach - tell Messages what you want it to do (send a message) not necessarily how you would do it (click here, type this, etc.)


For example, to send a message to a buddy you can:


tell application "Messages"

set theBuddy to buddy "someone@mac.com" of service "iCloud"

send "Hi there" to theBuddy

end tell


(adjust for your appropriate service name, of course.

22 replies

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.

AppleScript to send new iMessage

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