Advice on Converting to External Files from Embedded Scripts

Posted on
Tue Sep 13, 2016 12:02 pm
dawson1331 offline
Posts: 32
Joined: Oct 22, 2012

Advice on Converting to External Files from Embedded Scripts

I have always used embedded scripts for my actions. But now some actions are taking longer than the 10 seconds allowed. So I would like some advice on how to convert my scripts to external files. I use both Applescripts and Python. My typical senario is to create a script file with lots of subroutines/handlers. I put them in the Indigo script/attachments directory or the python directory. Then from the actions I would call the subroutine as an embedded script. For example:
Example Script File in the Attachments Directory:


WindowBlinds.scpt

on openWindow(window)

end openWindow

on closeWindow(window)

end closeWindow

plus lots of supporting subroutines

end script


In the Indigo actions I would use an embedded script - triggered by a button press for example:
openWindow(1)


So how I do I convert that to an embedded file?
Do I write a one line program file to open a window?
Do I have to write a different file to open/close each window? - there could be a lot.
Is there a way to pass parameters to an external file? Indigo Variables?
How do you “import” the handlers from the Applescript? Python looks easier for import.
The example external script files seem to start and run forever. But I can not see how to apply that in my case.

Thanks.

Posted on
Sun Sep 18, 2016 10:09 am
matt (support) offline
Site Admin
User avatar
Posts: 21411
Joined: Jan 27, 2003
Location: Texas

Re: Advice on Converting to External Files from Embedded Scr

I would suggest using Python over AppleScript. It sounds like maybe you are already doing this, but here is some documentation on sharing classes/methods using Python.

Either technique (AppleScript or python) has the issue of how to pass arguments (window identifier in this case) to the external script file. If you have the methods in a file in the site-packages folder (outlined in documentation linked above), then I would probably just create 1-line external .py files that call that method with the ID you want to specify. There might be a lot of them, but you can just duplicate them and change the ID when you need to add a new one.

You could set an Indigo variable value in Indigo's action list to be executed before the script is called, then have the script retrieve the value of the Indigo variable value. The same page above has a section on using Indigo variables in Python. The gotcha with this technique is if you have multiple actions executes around the same time. In that case it might be possible that the variable value gets changed before the script has the opportunity to retrieve the value.

Image

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 3 guests