Skip to content

Instantly share code, notes, and snippets.

@xoebus
Last active October 21, 2017 06:41
Show Gist options
  • Save xoebus/2376590 to your computer and use it in GitHub Desktop.
Save xoebus/2376590 to your computer and use it in GitHub Desktop.
Send iMessages from the Command Line

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
warn "Error: No buddy with that address."
exit 1
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}"
@Leckatall
Copy link

Leckatall commented Sep 27, 2017

I get the error:
/usr/bin/env: ‘macruby’: No such file or directory

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