Page 1 of 1

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

PostPosted: Fri Jun 07, 2019 1:52 am
by billearl
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'"

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

PostPosted: Fri Jun 07, 2019 9:18 am
by jay (support)
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.