Changing Indigo Variables with AppleScript

Posted on
Wed Jul 19, 2023 8:52 pm
Dave Durham offline
Posts: 23
Joined: Nov 30, 2003
Location: Los Angeles, CA

Changing Indigo Variables with AppleScript

OK...yes, I know, I know...I should switch to Python...but for now I have hundreds of AppleScripts that need to work with Indigo and maybe eventually I'll properly change them. So...
I have a way to have my AppleScript scripts read and write to Indigo Variables via my Reflector. But I can't believe this is the fastest/best way to do this. It works, but it takes a second or two (as opposed to instant the way it used to when the server was scriptable). So, my question is, is there a faster/better way to read and write Indigo Variables via AppleScript? Here is the way I do it now:


Code: Select all
To Write an Indigo Variable via AppleScript:

on sendToIndigo(theValue, variableID)
   set theValue to cleanUpString2(theValue) --This just gets rid of \ and ' characters
   set sideShell to "curl -X POST -H \"Authorization: Bearer  MyAuthorizationCodeGoestHere\" -d '{\"message\": \"indigo.variable.updateValue\", \"objectId\": " & variableID & ", \"parameters\": {\"value\": \"" & theValue & "\"}}' https://ReflectorNameHere.indigodomo.net/v2/api/command"
   do shell script sideShell
end sendToIndigo



To Read an Indigo Variable via AppleScript:

Code: Select all
--Currently limitied to 2000 Characters in the return
on getFromIndigo(variableID)
   set sideShell to "curl -H \"Authorization: Bearer MyAuthorizationCodeGoesHere\" https://ReflectorNameHere.indigodomo.net/v2/api/indigo.variables/" & variableID
   try
      set VariableInformation to do shell script sideShell
      
      set characterPosition to 1
      set valuePosition to 1
      set variableValue to ""
      
      repeat 300 times
         if character characterPosition of VariableInformation = "v" then
            set wordCheck to (characters characterPosition thru (characterPosition + 4) of VariableInformation) as string
            if wordCheck = "value" then
               set valuePosition to characterPosition + 9
               
               if ((character valuePosition of VariableInformation) as string) = "\"" then
                  --The value is BLANK
                  set variableValue to ""
               else
                  --The vlaue is NOT BLANK
                  
                  repeat 2000 times
                     set variableValue to (variableValue & character valuePosition of VariableInformation) as string
                     
                     set valuePosition to valuePosition + 1
                     if character valuePosition of VariableInformation = "\"" then exit repeat
                  end repeat
                  
               end if
            end if
         end if
         if valuePosition is not 1 then exit repeat
         set characterPosition to characterPosition + 1
      end repeat
      
      return variableValue
   on error
      --There was a problem getting the Variable from Indigo
   end try
end getFromIndigo




Any help / insight would be appreciated.
Thank you kindly,
Dave Durham

Posted on
Thu Jul 20, 2023 7:23 am
jay (support) offline
Site Admin
User avatar
Posts: 18225
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Changing Indigo Variables with AppleScript

Two points:

  • You don't have to use the reflector - since you're running the script on the same Mac, you can just use http://localhost:8176/
  • The Indigo Control AppleScript should be faster than using the reflector - not sure if it'll be faster than using localhost though since it has to launch an IPH instance for each script

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Jul 20, 2023 7:33 am
jay (support) offline
Site Admin
User avatar
Posts: 18225
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Changing Indigo Variables with AppleScript

One more: after editing your post to put code tags around your AppleScript (which you should always do), I admit I don't understand exactly what the function that gets an Indigo is doing, but it's potentially doing a TON of looping. AppleScript isn't very fast, so I'm a little surprised it ever worked quickly. I suspect you'd get a big performance boost by converting that to Python. We could help if you could explain what it's trying to do.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Fri Jul 21, 2023 11:17 am
Dave Durham offline
Posts: 23
Joined: Nov 30, 2003
Location: Los Angeles, CA

Re: Changing Indigo Variables with AppleScript

Jay, Thank you for the reply. and as usual, you're right on both counts. I'll circle back to implement when I return from my trip.

Thank you kindly,
-d

Posted on
Fri Jul 21, 2023 12:11 pm
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Changing Indigo Variables with AppleScript

jay (support) wrote:
One more: after editing your post to put code tags around your AppleScript (which you should always do), I admit I don't understand exactly what the function that gets an Indigo is doing, but it's potentially doing a TON of looping. AppleScript isn't very fast, so I'm a little surprised it ever worked quickly. I suspect you'd get a big performance boost by converting that to Python. We could help if you could explain what it's trying to do.


He's looping through the JSON response looking for the "value" key (and value).

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 9 guests