Skip to content

Instantly share code, notes, and snippets.

@alekhinen
Created July 21, 2015 18:52
Show Gist options
  • Save alekhinen/9b4c3e101c9d4419b9d0 to your computer and use it in GitHub Desktop.
Save alekhinen/9b4c3e101c9d4419b9d0 to your computer and use it in GitHub Desktop.
Programmatically send an iMessage from Terminal
on run {targetBuddyPhone, targetMessage}
tell application "Messages"
set targetService to 1st service whose service type = iMessage
set targetBuddy to buddy targetBuddyPhone of targetService
send targetMessage to targetBuddy
end tell
end run
@alekhinen
Copy link
Author

This sends an iMessage to a buddy. Note: If the number you specify isn't in your buddy list, then the command will fail. For security reasons, Apple does not allow you to programmatically start a conversation with a new buddy. However, there is a workaround for this - see https://gist.github.com/alekhinen/b3a112cfbb5cad70e6e2. It's a bit kludgy as it opens up the Messages app and goes through the UI to send a new message, but it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment