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