Send iMessages from the Command Line
Just run the following in your shell:
$ curl https://raw.github.com/gist/5737556/imsg.rb > ~/bin/imsg
The same command will update the script if/when I update it.
$ 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 | |
exit "Error: No buddy with that address." unless buddy | |
msg = ARGV[1] | |
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}" |