| Author |
Message |
|
dstrickler
Joined: Oct 08, 2010 Posts: 246 Location: Boston, MA
|
 How many external AppleScripts can be run at once?
I have two kids, and they each have an Action Group that calls out to an external script file that does a sunrise simulation (raises the lights in the room about 2%, waits 60 seconds, and repeats). Each of these Action Groups is called by a Schedule that fires it off - one at 6:31am and the the other at 6:32am (just to be safe). The problem is that if these scripts overlap in timing (each runs for 30 minutes), than when the second one goes to startup, it never seems to execute the external script. This leads me to believe that Indigo only has one external thread for running stand-along script files, but I can't really believe that's the case. Enclosed below is a log file. I fired the schedules off myself in a test just to prove to myself it was happening. Notice Grayson's was fired off first, and his continues to run, but Hailey's was fired off second, and although the Action Group seems to kick off, the script isn't running as you should see similar entries in the log. And yes, I watched the lights, and they didn't go on for Hailey. Any clues on this? - Code: Select all
Dec 7, 2011 11:31:55 AM Schedule Grayson's Sunrise Simulator Action Group Grayson's Sunrise Simulator Script Starting to raise the lights by 2% every 30 seconds over the next 30 minutes to achive a final brightness of 90 Script Sunrise Simulator raised Grayson's Overhead Light Dresser to 0% Sent INSTEON "Grayson's Overhead Light Dresser" on to 2 Schedule Hailey's Sunrise Simulator Action Group Hailey's Sunrise Simulator
Dec 7, 2011 11:32:26 AM Script Sunrise Simulator raised Grayson's Overhead Light Dresser to 2% Sent INSTEON "Grayson's Overhead Light Dresser" on to 4
Dec 7, 2011 11:32:56 AM Script Sunrise Simulator raised Grayson's Overhead Light Dresser to 4% Sent INSTEON "Grayson's Overhead Light Dresser" on to 6
_________________ Dave
|
| Wed Dec 07, 2011 10:42 am |
|
 |
|
jay (support)
Site Admin
Joined: Mar 19, 2008 Posts: 6642 Location: Austin, Texas
|
 Re: How many external AppleScripts can be run at once?
External scripts are started in their own processes so they should run concurrently. I just did a simple test: two scripts, each of which logs a line and delays a second repeatedly. Here's the first bit of log: - Code: Select all
Dec 7, 2011 11:21 AM Action Group Multiple stay-open applescripts AppleScript 1 Test from first script AppleScript 2 Test from second script AppleScript 1 Test from first script AppleScript 2 Test from second script AppleScript 1 Test from first script AppleScript 2 Test from second script AppleScript 1 Test from first script AppleScript 2 Test from second script AppleScript 1 Test from first script AppleScript 2 Test from second script AppleScript 1 Test from first script
It went on until I killed the processes. Speaking of which, here is the process list: - Code: Select all
FatMac:IndigoPlugins jay$ ps -ax | grep "Logger" 49896 ?? 0:00.20 /usr/bin/osascript /Users/jay/temp/AS Logger 1.scpt 49897 ?? 0:00.20 /usr/bin/osascript /Users/jay/temp/AS Logger 2.scpt
And, finally, here's the script code from the first script (the second is almost identical with just wording changes): - Code: Select all
tell application "IndigoServer" repeat log "Test from first script" using type "AppleScript 1" delay 1 end repeat end tell
So, I'm not sure what's happening on your system but external AppleScripts are started in their own osascript process. Once the action group starts up both scripts, check to make sure that there are 2 different osascript processess.
_________________ Jay (Indigo Support)
|
| Wed Dec 07, 2011 11:27 am |
|
 |
|
dstrickler
Joined: Oct 08, 2010 Posts: 246 Location: Boston, MA
|
 Re: How many external AppleScripts can be run at once?
As usual, excellent info - thanks. I will check this out on the CLI and see what's happening.
_________________ Dave
|
| Wed Dec 07, 2011 11:39 am |
|
 |
|
dstrickler
Joined: Oct 08, 2010 Posts: 246 Location: Boston, MA
|
 Re: How many external AppleScripts can be run at once?
Sorry for the delay in this - I finally started doing some testing this morning with the kids out of the house. What I found interesting, is that I have no osascript processes running, and yet I can see one of the scripts logging (and thus running) in Indigo. Perhaps I am running the scripts differently? My scripts are more complex if that matters: There is a function I created called SunriseSimulation which sits in the Attachments sub-dir on the server and looks like this: - Code: Select all
using terms from application "IndigoServer" on SunriseSimulation(deviceName, maximumLightPercentage, minutesToSunrise) -- This math is importaint as it sets the number of repeats below set raiseLightsBy to round (maximumLightPercentage / minutesToSunrise / 2) log "Starting to raise the lights by " & raiseLightsBy & "% every 30 seconds over the next " & minutesToSunrise & " minutes to achive a final brightness of " & maximumLightPercentage repeat minutesToSunrise * 2 times -- Turn up the brightness of the device one increment brighten deviceName by raiseLightsBy -- Set a variable with the current brightness of our device so we can log it below set currentBrightness to brightness of device deviceName as integer log "Sunrise Simulator raised " & deviceName & " to " & currentBrightness & "%" -- Since the parameter minutesToSunrise is in minutes, delay one minute -- but loop every 30 seconds to give it a more even increase in -- brightening. Note the "minutesToSunrise / 2" and "repeat minutesToSunrise * 2 times" -- above to account for the half minute increment. delay 30 end repeat -- In case there is a rounding error above, set it to the target percentage brighten deviceName to maximumLightPercentage end SunriseSimulation end using terms from
This code is called from an Action Group called "Hailey's Sunrise Simulation" which is really calling an external (server-based) Applescript routine in the Scripts sub-dir that looks like: - Code: Select all
tell application "IndigoServer" SunriseSimulation("Hailey's Overhead Lights", 90, 30) end tell
So this works very well. The Action Group is called by a Schedule each school morning. But when the other Action Group calls "Grayson's Sunrise Simulation" that is an exact copy of the first one (except for the light/device name changed") it won't run at the same time. Regardless of which you start first, the second won't run until the first has finished. My lack of finding an osascript process running is what's bothering me the most. Is there something that needs to be enabled to make this happen?
_________________ Dave
|
| Tue Jan 10, 2012 7:57 am |
|
 |
|
jay (support)
Site Admin
Joined: Mar 19, 2008 Posts: 6642 Location: Austin, Texas
|
 Re: How many external AppleScripts can be run at once?
Because you defined SunriseSimulation as an Indigo attachment script, it's being executed on the main thread of the server and is therefore serialized (it's also hanging up other stuff as well). The external script should have all the logic in it (or in script objects loaded from the filesystem) - putting the delays in the attachment handler is basically the same as embedding it. Instead, you should use AppleScript's built-in method for loading script objects from the filesystem. This will keep the Indigo communication to a minimum. You should be seeing osascript processes for the external script executions though even though they're just bouncing the execution back to the Indigo server so I'm not sure what's going on there - when you execute an external script it starts up an osascript process that runs until the script exits (that's the only way it can execute).
_________________ Jay (Indigo Support)
|
| Tue Jan 10, 2012 10:22 am |
|
 |
|
dstrickler
Joined: Oct 08, 2010 Posts: 246 Location: Boston, MA
|
 Re: How many external AppleScripts can be run at once?
Thanks for the tips. Let me play around a little more and gather more info.
_________________ Dave
|
| Tue Jan 10, 2012 10:58 am |
|
 |
|
dstrickler
Joined: Oct 08, 2010 Posts: 246 Location: Boston, MA
|
 Re: How many external AppleScripts can be run at once?
Got it working! Your tips were spot on. Here's the code for each kid's script: - Code: Select all
tell application "IndigoServer" set deviceName to "Hailey's Overhead Lights" set maximumLightPercentage to 90 set minutesToSunrise to 30 -- This math is importaint as it sets the number of repeats below set raiseLightsBy to round (maximumLightPercentage / minutesToSunrise / 2) log "Starting to raise the lights by " & raiseLightsBy & "% every 30 seconds over the next " & minutesToSunrise & " minutes to achive a final brightness of " & maximumLightPercentage repeat minutesToSunrise * 2 times -- Turn up the brightness of the device one increment brighten deviceName by raiseLightsBy -- Set a variable with the current brightness of our device so we can log it below set currentBrightness to brightness of device deviceName as integer log "Sunrise Simulator raised " & deviceName & " to " & currentBrightness & "%" -- Since the parameter minutesToSunrise is in minutes, delay one minute -- but loop every 30 seconds to give it a more even increase in -- brightening. Note the "minutesToSunrise / 2" and "repeat minutesToSunrise * 2 times" -- above to account for the half minute increment. delay 30 end repeat -- In case there is a rounding error above, set it to the target percentage brighten deviceName to maximumLightPercentage end tell
Effectively I had to move the function into the main script code (stored in Scripts on the server) as I wasn't clear about calling the AppleScript code from your link. It's just on the edge of my coding knowledge, and since I'll be moving to Python soon enough, no need to try and learn it. Also, when I moved the code over to the method above, guess what I saw on CLI? - Code: Select all
dstrickler 60807 0.0 0.3 2467712 6292 ?? S 12:10PM 0:00.14 /usr/bin/osascript /Library/Application Support/Perceptive Automation/Indigo 5/Scripts/Hailey Sunrise Simulation.scpt dstrickler 60806 0.0 0.3 2467712 6300 ?? S 12:09PM 0:00.19 /usr/bin/osascript /Library/Application Support/Perceptive Automation/Indigo 5/Scripts/Grayson Sunrise Simulator.scpt
All looks working now. As usual, thanks for all your help. On a semi-related note, check your the New York Time online for an article on now Home Automation is become more and more of a "standard feature" in new homes (and some old ones too). I saw this and thought "These Indigo guys are in the right place at the right time".
_________________ Dave
|
| Tue Jan 10, 2012 11:19 am |
|
 |
|
jay (support)
Site Admin
Joined: Mar 19, 2008 Posts: 6642 Location: Austin, Texas
|
 Re: How many external AppleScripts can be run at once?
dstrickler wrote:On a semi-related note, check your the New York Time online for an article on now Home Automation is become more and more of a "standard feature" in new homes (and some old ones too). I saw this and thought "These Indigo guys are in the right place at the right time".
Link?
_________________ Jay (Indigo Support)
|
| Tue Jan 10, 2012 12:06 pm |
|
 |
|
dstrickler
Joined: Oct 08, 2010 Posts: 246 Location: Boston, MA
|
 Re: How many external AppleScripts can be run at once?
_________________ Dave
|
| Tue Jan 10, 2012 12:19 pm |
|
|