Hacker News new | ask | show | jobs
by aktau 4509 days ago
I immediately thought it would be cool to make some of my cronscripts send some messages to myself when something interesting happens. Sadly, the form used in this utility does not lend itself to sending to self, Messages.app returns an error when you try.

Turns out it's quite easy to get around, here's a gist that allows to you make a nice mini-commandline app: https://gist.github.com/aktau/8958054

(reproduced here):

  #!/bin/sh
  exec <"$0" || exit; read v; read v; exec /usr/bin/osascript - "$@"; exit
   
  -- taken from:
  -- http://stackoverflow.com/questions/11812184/how-to-send-an-imessage-text-with-applescript-only-in-provided-service
  -- thanks to users @Senseful and @DigiLord
  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
Now I can do:

  $ imessage XXXXXXXXXX "gofinance: stock AAPL went up, possibly because of imessage..."
Where XXXXXXXXXX is my own number.

There are some other cool hacks with this, among others is a Lisp REPL with iMessage: https://46b.it/2012/hacking-with-imessage.