Page 1 of 1

Help converting a simple AppleScript Serveraction to Python

PostPosted: Sun Jan 26, 2020 7:11 pm
by Dave G
Maybe I'm getting to be an old dog, but my programming days go back to C and Unix and I'm not up, at the moment, to hone my object-oriented programming skills.

I've got some simple AppleScript code embedded in a Server Action on a Control Page in Indigo that switches a Somfy shade remote control from Open to Close:

#
# The original AppleScript was:
#
# if (binary outputs of device "Guest BR roller shades") is equal to {false} then
# set binary outputs of device "Guest BR roller shades" to {true}
# else
# set binary outputs of device "Guest BR roller shades" to {false}
# end if
#

I know this is simple switch logic, but could somebody help me do a quick conversion to Python? Thanks so much.

Re: Help converting a simple AppleScript Serveraction to Py

PostPosted: Mon Jan 27, 2020 10:02 am
by jay (support)
Code: Select all
roller_shades = indigo.devices[1234567890] # "Guest BR roller shades" - substitute ID of this device
# If the first output of the device is True - your script implies a binary output device with only 1 output - so we get the first (and only) one.
# Note that you could write it "if roller_shades.binaryOutputs[0] is True", but since the values of the binaryOutputs list are booleans it's not necessary.
if roller_shades.binaryOutputs[0]:
    # the output is True so set it to False
    indigo.iodevice.setBinaryOutput(roller_shades, index=0, value=False)
else:
    # the output is False so set it to True
    indigo.iodevice.setBinaryOutput(roller_shades, index=0, value=True)