Page 1 of 4

Messages app plugin

PostPosted: Wed Jan 27, 2016 2:39 pm
by gazally
Here's my first plugin, which lets Indigo send and receive messages with the OS X Messages app. I wrote it because I wanted to make turning the water on and off at our vacation house super simple for my non-techie family members. And I wanted to learn Python and it seemed like a good little project.

The basic idea is that you set up a device to send and receive messages. Received messages can be retrieved from the device state, and there are plugin actions to mark a message as read and to send outgoing messages.

For both instructions and the download, see: https://github.com/gazally/indigo-messages

The plugin relies on an Applescript handler to collect messages and pass them onto Indigo so installation is a tad more complicated than usual, but I've put instructions in the github README for how to do it. It seems likely that Applescript handler support is not very high priority for the Messages development team at Apple because the El Capitan version, the only one I've tried it on, has a couple of bugs. I don't have a solution for either one of them, but they're not hard to work around either. See the end of the README for details.

Re: Messages app plugin

PostPosted: Wed Jan 27, 2016 3:59 pm
by jay (support)
Nice, thanks for the contribution!

It occurs to me that if you're running Yosemite or better you probably can send TXT messages as well since continuity would just pass it over to your iPhone (if you have one that is). Hmmmm...

Re: Messages app plugin

PostPosted: Wed Jan 27, 2016 4:11 pm
by jay (support)
And, yes, it does seem like the trend at Apple over the past several years is to allow AppleScript to languish. This is no small part of the reasoning why we've moved away from it to Python as our scripting language.

Re: Messages app plugin

PostPosted: Thu Jan 28, 2016 6:48 am
by Bollar
This is awesome!

I have been waiting so long for this.

Re: Messages app plugin

PostPosted: Thu Jan 28, 2016 7:28 am
by jalves
This looks like it could be very useful. I'm going to have to try it out. Thanks for the development effort!

Re: Messages app plugin

PostPosted: Thu Mar 24, 2016 12:11 pm
by kadluvu
My objective will be pretty simple. I get a lot of text messages sent to me via sending an e-mail notification. It works great, but EVERY message has a unique number from ATT (Sending an e-mail to phone number@txt.att.net. I'm hoping this plugin will enable me to send notifications and have them all nested as from my AppleID.

~ Easy setup and now my messages are nested! Very nice.

Re: Messages app plugin

PostPosted: Fri Mar 25, 2016 11:06 am
by Seeker
Thank you for this plugin. i just installed it and setup a test action and it seems to work great!

Re: Messages app plugin

PostPosted: Mon Mar 28, 2016 10:56 am
by gazally
I just put a ridiculously minor update up, to fix a bug that was leading to duplicate lines in my daily chatlog report. If anyone might find it helpful, here's the script I'm using to get a daily email containing all of Indigo's communications using the Messages plugin. It requires the SQL Logger plugin and I have it on a schedule running just before midnight:

Code: Select all
import sqlite3

def format_lines(rows):
    results = []
    rows = sorted(rows, key=lambda tup:tup[1])
    for r in rows:
        date, time, name, msg, resp, st1, st2 = r
        if st2 == "New":
            results.append("{0} {1}> {2}".format(time, name, msg))
        else:
            results.append("{0} Indigo> {1}".format(time, resp))
    return results

logpath = indigo.server.getInstallFolderPath() + "/Logs"
db = logpath + "/indigo_history.sqlite"
conn = sqlite3.connect(db)
c = conn.cursor()

chatlog = []
for dev in indigo.devices.iter("me.gazally.indigoplugin.Messages"):
    chatlog.extend(c.execute("SELECT date(ts, 'localtime'), time(ts, 'localtime'), name, message, response, responsestatus, status FROM device_history_" + str(dev.id) + " WHERE date(ts, 'localtime')=date('now', 'localtime') AND (status='New' OR responsestatus='Sending')"))

conn.close()
if chatlog:
    indigo.server.sendEmailTo("xxxx@xxxx.com", "Indigo daily chatlog", "\n".join(format_lines(chatlog)))


Re: Messages app plugin

PostPosted: Mon Mar 28, 2016 11:48 am
by petematheson
Nice work on this one! Following for future updates but all seems to be working well so far on El Capitan :D

Re: Messages app plugin

PostPosted: Fri Apr 15, 2016 3:24 pm
by Seeker
Can you explain the 'mark as read' deal? The plugin works great, but the messages don't show up as new.

Re: Messages app plugin

PostPosted: Fri Apr 15, 2016 7:09 pm
by Different Computers
Very cool!

FYI Matt, Continuity would only work in the oddest use case for this plugin: when you're at home near your server.

Continuity won't work if you're out of the house, unless you left your phone at home!

Re: Messages app plugin

PostPosted: Sun Apr 17, 2016 12:22 pm
by gazally
My Indigo installation has its own iCloud account. Maybe Matt's has its own iPhone :P

Seeker, I'm not really sure what your question is. When a message arrives the device state should go to New and stay there until you use the Mark as Read action. If additional messages arrive after the first one, they will wait for you to use Mark as Read before overwriting the first one.

The reason for "Mark as Read" is to make the message device states stick around so that you can use them in actions attached to a trigger without the risk that a new message will arrive and cause the device states to be overwritten before the actions have had a chance to read them. Because if a plugin or device used in one of your actions is busy when a trigger fires, Indigo will queue that action up as work to be done later and possibly do all kinds of other stuff before that action actually happens. This is mostly a concern with my Chatbot plugin, which could potentially be running some time-consuming Python script in response to the last message when the new one arrives.

Re: Messages app plugin

PostPosted: Sun Apr 17, 2016 1:20 pm
by petematheson
I'm constantly getting the 'Wait' prompt after a few messages at random times. Once it does it, the rest of the messages just queue up behind until I manually log on and click through all the wait messages. Any ideas how to stop this?
It's not the front window thing as I always click a few windows in front of messages just to be sure.

Re: Messages app plugin

PostPosted: Sun Apr 17, 2016 5:03 pm
by Seeker
gazally wrote:
Seeker, I'm not really sure what your question is. When a message arrives the device state should go to New and stay there until you use the Mark as Read action. If additional messages arrive after the first one, they will wait for you to use Mark as Read before overwriting the first one.

The reason for "Mark as Read" is to make the message device states stick around so that you can use them in actions attached to a trigger without the risk that a new message will arrive and cause the device states to be overwritten before the actions have had a chance to read them. Because if a plugin or device used in one of your actions is busy when a trigger fires, Indigo will queue that action up as work to be done later and possibly do all kinds of other stuff before that action actually happens. This is mostly a concern with my Chatbot plugin, which could potentially be running some time-consuming Python script in response to the last message when the new one arrives.


My issue is that the messages sent by the plugin ARRIVE as read. They are never not read.

Re: Messages app plugin

PostPosted: Mon Apr 18, 2016 8:46 am
by gazally
Seeker, are you sure you don't have a Mark as Read action hiding in a trigger somewhere? I notice I omitted a debugLog message in that action, which I'll remedy, but that's the only place in the code where message status gets sent to Read.

Pete, I haven't encountered a Wait prompt. Is it coming from Messages or Indigo?