parameters from indigo to applescript

Posted on
Sat Jun 01, 2013 7:03 am
kw123 offline
User avatar
Posts: 8366
Joined: May 12, 2013
Location: Dallas, TX

parameters from indigo to applescript

is there a way besides

tell application "indigoserver"
set xx to (get value of variable "xyz")
end tell

to get parameters as part of the call to the applescript?

Thanks

Karl

Posted on
Sat Jun 01, 2013 12:33 pm
jay (support) offline
Site Admin
User avatar
Posts: 18224
Joined: Mar 19, 2008
Location: Austin, Texas

Re: parameters from indigo to applescript

Sorry, there's not enough context in your question to answer it effectively. Are you trying to get Indigo data into a separate AppleScript that's not running embedded or executed from Indigo?

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sat Jun 01, 2013 9:35 pm
kw123 offline
User avatar
Posts: 8366
Joined: May 12, 2013
Location: Dallas, TX

Re: parameters from indigo to applescript

in my old fortran language: call myapplescript(parm1, parm2), where I would like to use a copy of the values of parm1,parm2. parm 1,2 then they can change after (outside myapplescript) the call is initiated

Karl

I guess, I have outed my age..
or better in assembler push parameters onto stack and jmp to subroutine

Posted on
Sun Jun 02, 2013 10:11 am
jay (support) offline
Site Admin
User avatar
Posts: 18224
Joined: Mar 19, 2008
Location: Austin, Texas

Re: parameters from indigo to applescript

Hmmm - still not sure I'm following, particularly this part:

parm 1,2 then they can change after (outside myapplescript) the call is initiated


Certainly, you can have AppleScript handlers defined in Attachment scripts so you could create a myapplescript(p1, p2) handler, but I'm not sure that's what you're really asking for.

Can you give me a specific example? Don't worry about syntax just give me the real-world scenario that you're trying to address and maybe I can follow that.

To be perfectly honest with you, if you're just learning AppleScript and Indigo Scripting, I would highly recommend learning Python and using the IOM instead - it's more complete and will continue to grow with the product (AppleScript is legacy and isn't being added to so any new features since Indigo 4 won't be available there).

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sun Jun 02, 2013 10:28 am
kw123 offline
User avatar
Posts: 8366
Joined: May 12, 2013
Location: Dallas, TX

Re: parameters from indigo to applescript

Jay,
in trigger/actions/server action/ script and file actions/ menu I can choose a file to be executed.

would like to have a field where I can add a parameter for this execution of the script file, the script can pick up.

I know how to do it in 2 action steps: first action set a general variable in indigo then second action execute a script. and the script picks up that variable.
Is there a timing issue doing it this way, i.e. is the variable always set before the next steps starts?

thanks

Karl


ps just realized you live in Austin. I live in Rainey Street, but after 2+years moving back home to Dallas this coming week. Finally retiring :)

Posted on
Sun Jun 02, 2013 10:41 am
jay (support) offline
Site Admin
User avatar
Posts: 18224
Joined: Mar 19, 2008
Location: Austin, Texas

Re: parameters from indigo to applescript

There are a couple of different actions that run scripts: Execute Script, which will execute an embedded Python or AppleScript or will execute a Python or AppleScript stored in a file. The other is the Run Shell Script action.

The Execute Script action, as I mentioned, will execute scripts in two ways: you can type your script into the Embedded script text box and Indigo will execute them. Any script there (Python or AppleScript) will have direct access to Indigo objects (AppleScript missing some newer features as I mentioned before). You can also have it execute a Python or AppleScript file - this won't allow you to pass any parameters but the scripts will have full access to Indigo objects as well.

Because I don't know what it is exactly you're trying to do, I can't really tell whether this would be appropriate for your scenario or not. Describing exactly what you're trying to do would help. State the requirements, not the implementation - then we can help you get to a solution.

The latter action, Run Shell Script, will simply run the script specified - no parameters, just execute the script.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sat Aug 31, 2013 1:59 pm
kw123 offline
User avatar
Posts: 8366
Joined: May 12, 2013
Location: Dallas, TX

Re: parameters from indigo to py, call external py script

how can I "call" a python script file in an action / trigger multiple times:

I have a python script "setCameraLevels.py" (that works as embedded script)
it is copied into usr/Libray/Phyton/2.5/sitep-packages as well as into ...indigo 6/Scripts/Attachments


would like to put this into the embedded python script (scheduled action) with different numbers depending on day/night and camera location
setCameraLevels(theIPnumber='192.168.1.71', Brightness=1, Contrast=1, Saturation=1, Antiflicker=1, MirrorOnOff=0)
setCameraLevels(theIPnumber='192.168.1.73', Brightness=5, Contrast=0, Saturation=1, Antiflicker=1, MirrorOnOff=0)
...
setCameraLevels(theIPnumber='192.168.1.78', Brightness=3, Contrast=3, Saturation=0, Antiflicker=1, MirrorOnOff=0)


I get error "embedded script: global name 'setCameraLevels' is not defined"

The execution of each of the calls might take longer as the cameras sometimes takes time to answer - as embedded script, I run into timeouts and block indigo progress until its finished.

I have an equivalent setup with applescript in attachments that works, would like to learn how to do this in py.

attached the setCameraLevels.py
thx

Karl

Code: Select all
import urllib2
def setCameraLevels(theIPnumber="192.168.1.71", Brightness=0, Contrast=0, Saturation=0, Antiflicker=1, MirrorOnOff=0):
   map = ["1", "14", "26", "39", "51", "64", "77", "90", "193", "115", "128"]
       
   if Brightness >= 6: Brightness = 5
   if Brightness <= -6: Brightness = -5
   setBrightness = map[(Brightness +5)]
   
   if Contrast >= 6: Contrast = 5
   if Contrast <= -6: Contrast = -5
   setContrast = map[(Contrast +5)]
   
   if Saturation >= 6: Saturation = 5
   if Saturation <= -6: Saturation = -5
   setSaturation = map[(Saturation +5)]
   
   if Antiflicker >= 1: setAntiflicker = '1'
   if Antiflicker <= 0: setAntiflicker = '0'
   
   if MirrorOnOff >= 1: setMirrorOnOff = '1'
   if MirrorOnOff <= 0: setMirrorOnOff = '0'
   
   
   data = "&ReplySuccessPage=image.htm"
   data = data + "&ReplyErrorPage=errrimg.htm"
   data = data +"&BrightnessControl="+ setBrightness
   data = data +"&ContrastControl="+setContrast
   data = data +"&SaturationControl="+setSaturation
   data = data +"&AntiFlickerEnable="+setAntiflicker
   data = data +"&Mirror="+setMirrorOnOff
   data = data +"&ConfigSystemStream=Save"
   
   url = 'http://'+theIPnumber+'/setSystemStream'
   theUserid="uuuu"
   thePassword="pppp"
   passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
   passman.add_password(None, url, theUserid, thePassword)
   urllib2.install_opener(urllib2.build_opener(urllib2.HTTPBasicAuthHandler(passman)))
   response = urllib2.urlopen(url=url,data=data).read

Posted on
Sun Sep 01, 2013 9:39 am
jay (support) offline
Site Admin
User avatar
Posts: 18224
Joined: Mar 19, 2008
Location: Austin, Texas

Re: parameters from indigo to applescript

The scripting tutorial has a section about libraries. I think all you're missing it an import statement (you have to explicitly import your shared script). At the top of your embedded script:

Code: Select all
import setCameraLevels  #file name without .py at the end is the module


When you call the method:

Code: Select all
# syntax is modulename.methodname()
setCameraLevels.setCameraLevels(PARAMS)

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 32 guests