Skip to content

Instantly share code, notes, and snippets.

@andermoran
Created April 12, 2017 18:41
Show Gist options
  • Save andermoran/9f4bfb245f9498a7105b53b63a57cbb8 to your computer and use it in GitHub Desktop.
Save andermoran/9f4bfb245f9498a7105b53b63a57cbb8 to your computer and use it in GitHub Desktop.

Revisions

  1. andermoran created this gist Apr 12, 2017.
    19 changes: 19 additions & 0 deletions sendMessageThruTerminal.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    #!/bin/sh
    USAGE=$'Usage: imessage <number> <text>\nExample: message 9121231234 \"Hello!\"'
    if [ "$#" -ne "2" ]; then
    echo "$USAGE"
    exit 1;
    fi
    exec <"$0" || exit;
    for i in {1..12} # Reads the first x lines of the program
    do
    read v
    done
    exec /usr/bin/osascript - "$@"; exit # Interprets the following lines as AppleScript
    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