Skip to content

Instantly share code, notes, and snippets.

@wongjustin99
Forked from xoebus/README.md
Last active December 29, 2015 13:59
Show Gist options
  • Save wongjustin99/7681252 to your computer and use it in GitHub Desktop.
Save wongjustin99/7681252 to your computer and use it in GitHub Desktop.

imsg

Send iMessages from the Command Line


Install

Just run the following in your shell:

$ curl https://raw.github.com/gist/2376590/imsg.rb > ~/bin/imsg
$ chmod +x ~/bin/imsg

The same command will update the script if/when I update it. It also assumes that ~/bin is in your path.

Usage

$ imsg <recipient e-mail/phone no.> <message>
#!/usr/bin/env macruby
# imsg - Send iMessages from the command line.
#
# Usage: imsg <recipient e-mail/phone> <message>
framework 'ScriptingBridge'
# Scripting Bridge is hella cool.
messages = SBApplication.applicationWithBundleIdentifier('com.apple.iChat')
buddies = messages.buddies
buddy = buddies.find do |b|
b.id.include? ARGV[0]
end
unless buddy
puts "Error: No buddy with that address."
exit
end
msg = ARGV[1..-1].join(" ")
messages.send msg, :to => buddy
# Hide the opened application.
command = "'tell application \"System Events\"\nset visible of process \"Messages\" to false\nend tell'"
system "osascript -e #{command}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment