Scripting Indigo with Python

I’ve used Indigo home automation software for a few years. It’s a integrated home automation software environment for the Mac and its a solid stable and well-supported platform.

Within Indigo, it’s possible to script triggers and actions either AppleScript or Python. It’s funny - AppleScript often looks like the easier route to take. It looks more like plain English than Python. But as they say, looks are deceiving. Two bits of bad news put the nail in AppleScript’s coffin for me - as least with Indigo.

First, I kept encountering a nasty bug when trying to talk to the Indigo Server via AppleScript run outside of the Indigo environment. You can read all about it on the Indigo forums, but basically AppleScript complained that Indigo Server wasn’t running when it plainly was running. I’m not usually one for complex workarounds such as thus that were being discussed on the forums.^[For example, some users have reported that restarting the AppleEvents daemon with sudo killall -9 appleeventsd can somehow allow external AppleScript applications to address the Indigo Server. It didn’t work for me.] So, I began to give Python a consideration.

Then there’s the iffy status of AppleScript coming out of Cupertino. The recent departure of Apple’s head of Mac automation technologies and the fact that Apple dissolved the whole Mac automation team doesn’t bode well for AppleScript.

Setting up to talk to Indigo via the Indigo Plugin Host (IPH) and Python

To make it easier to address the indigohost which is buried ddep in the Application Support directory, you should just create an alias.

~|echo "alias indigohost='/Library/Application\ Support/Perceptive\ Automation/Indigo\ 7/IndigoPluginHost.app/Contents/MacOS/IndigoPluginHost'" >> ~/.zshrc
~|source ~/.zshrc

I happen to use zsh so your terminal environment may be different.

Now to try out the indigohost:

indigohost -e 'return indigo.devices.len()'

This should return the number of devices you have. Now you can script Indigo in Python both from within the Indigo client context and as an external application.

To run a Python application as a separate file, it’s just:

indigohost -x iphtest.py

Resources

Here are a few resources to get you started:

Good luck and have fun!