Get variable attribute using restful without parsing

Posted on
Wed Mar 28, 2012 1:49 am
gregconnors offline
Posts: 22
Joined: May 10, 2008
Location: Mayfield, Australia

Get variable attribute using restful without parsing

Hi.

Quick question I can't find an answer to: is it possible to use restful to get an attribute/value of a variable without parsing the XML/HTML/TXT page?

Reason being, I don't know how to parse the result (I'm assuming it's quite involved), when all I need is the value of the variable. I have to do it this way, because I'm running an script using cron from a remote machine. I need to get the value of the variable to decide if I want to change it.

I hope that makes sense.

Cheers,
Greg

P.S. I have thought about introducing a second variable and doing the checking using a trigger back on the server but I thought this might be quicker and simpler if it already exists.

Posted on
Wed Mar 28, 2012 5:10 am
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

Re: Get variable attribute using restful without parsing

Hi Greg,

Not via the RESTful API, but you can use Indigo's plugin host command line process to extract it. For example, this will return the value of the variable isDaylight:

Code: Select all
indigohost -e 'return indigo.variables["isDaylight"].value'


Note you need to set up the alias for indigohost as detailed on the plugin host command line page referenced above, or you can directly specify the absolute path:

Code: Select all
/Library/Application\ Support/Perceptive\ Automation/Indigo\ 5/IndigoPluginHost.app/Contents/MacOS/IndigoPluginHost -e 'return indigo.variables["isDaylight"].value'


If you need to execute that on a remote machine, and presuming you have SSH enabled on your Indigo Mac, then you can do something like:

Code: Select all
ssh USERNAME@INDIGO_MAC_IP "/Library/Application\ Support/Perceptive\ Automation/Indigo\ 5/IndigoPluginHost.app/Contents/MacOS/IndigoPluginHost -e 'return indigo.variables[\"isDaylight\"].value'"

Image

Posted on
Wed Mar 28, 2012 8:02 am
gregconnors offline
Posts: 22
Joined: May 10, 2008
Location: Mayfield, Australia

Re: Get variable attribute using restful without parsing

Thanks Matt for your super fast and thorough response, as always.

I haven't opened the server up for SSH, but this is as good a time as any. I'll give it a try in the morning and let you know how I go. Thanks again.

Greg.

Posted on
Wed Mar 28, 2012 5:59 pm
gregconnors offline
Posts: 22
Joined: May 10, 2008
Location: Mayfield, Australia

Re: Get variable attribute using restful without parsing

Morning all.

I'm having some difficulty with a couple of issues:
1. I tried to shortcut the indigo host (as in the plugin tutorial) and it works fine on the local machine, but not recognised/found when ssh'ed from the remote machine.
2. I think I've half worked out the extra set of quotes and backslashes for the 'do shell script' addition, so my code is:

Code: Select all
set x to do shell script "ssh media@192.168.0.3 \"/Library/Application\\ Support/Perceptive\\ Automation/Indigo\\ 5/IndigoPluginHost.app/Contents/MacOS/IndigoPluginHost -e 'return indigo.variables[\"isDaylight\"].value'\""


however, Indigo is giving an error:
Code: Select all
  Script Error                    embedded script: global name 'isDaylight' is not defined
  Script Error                    Exception Traceback (most recent call shown last):

     embedded script, line 1, at top level
NameError: global name 'isDaylight' is not defined


I'm assuming its a quote/backslash thing, but for the life of me, I can't get it.

Thanks, Greg.

Posted on
Wed Mar 28, 2012 6:46 pm
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

Re: Get variable attribute using restful without parsing

Yeah, quoting that ssh command from an embedded AppleScript is going to be a mess.

I thought you were calling it from a cron script? Can you explain the setup and why you need to use an embedded script in Indigo to access IndigoServer running on a different Mac. Seems complicated. :-)

Image

Posted on
Wed Mar 28, 2012 11:08 pm
gregconnors offline
Posts: 22
Joined: May 10, 2008
Location: Mayfield, Australia

Re: Get variable attribute using restful without parsing

Sorry Matt. You're right, it is complicated. Maybe I need to approach it a different way.

Essentially my situation is that my partner and myself do shift work and are our schedules are very different. I have our rosters in iCal in separate calendars. I have an Applescript that checks the calendars each night to work out if someone is working dayshift, or nightshift (and have corresponding Indigo variables). Reason being that if one of us has worked nightshift, I test those variables, to quarantine launching certain actions (e.g. music/sound, opening curtains, etc) in case we are sleeping.

I do have a 'sleep' mode, but the spouse is reluctant to use it (in fact, spousal resistance is very high to any automation), and more likely, being tired after 14-hour night shift, last thing you want to think about is having to turn everything off (even if it is only 1 button on the bedroom wall :-( ).

The reason its on a remote machine is my calendars are on my office iMac and not on my server. The script is executed on the iMac nightly and updates IndigoServer. I find it easier to deal with iCal scripting locally. Remote scripting is not easy for me. I suppose I could subscribe to the calendars on the server and update locally, but I was trying to keep my server as 'light' as possible. The cron entry merely launches the Applescript.

I hope that all makes sense. Thanks again. Greg.

Posted on
Thu Mar 29, 2012 8:17 am
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Get variable attribute using restful without parsing

I think the easiest solution is to subscribe to the calendars on your server Mac. There really isn't much overhead to it (iCal is pretty light) and its going to make your logic much more centralized. IMO... :)

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 12 guests