Get a device's on state from Python in an AppleScript?

Posted on
Fri Jun 07, 2019 1:52 am
billearl offline
Posts: 26
Joined: Aug 16, 2005

Get a device's on state from Python in an AppleScript?

I'm clueless in Python and would prefer to stay with AppleScript for the simple tasks I do with Indigo.

How can I pass the on state of a device from Python to AppleScript? Something like:

Code: Select all
set iphPath to "/Library/'Application Support/Perceptive Automation/" & ¬
   (name of application id "INDC") & "'/IndigoPluginHost.app/Contents/MacOS/IndigoPluginHost"

set deviceOnState to do shell script iphPath & " -e 'dev = indigo.devices[112943280]; dev.onState'"

Posted on
Fri Jun 07, 2019 9:18 am
jay (support) offline
Site Admin
User avatar
Posts: 18212
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Get a device's on state from Python in an AppleScript?

You're just missing a print statement when you get the device property which would send it to standard out (which is what do shell script will return to AppleScript). Here's a simplified version for Indigo 7.3 (note the simpler path to start a host process):

Code: Select all
set deviceOnState to do shell script "/usr/local/bin/indigo-host -e 'print(indigo.devices[112943280].onState)'"


This is quite inefficient though because it's starting up a full host process for each call that you make (that's somewhat resource intensive). Have you actually tried getting help converting one of your AppleScripts to Python? You might find that it's really easier and less complicated than you think, particularly if the script is so simple - it may just be a couple of lines of Python.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Page 1 of 1

Who is online

Users browsing this forum: Google [Bot] and 0 guests