Can a Script call itself


(Lenny Eiger) #1

Hello all, I have a script that calls another script (called docLoader, referenced in the docLoaderPath variable.

I have two other variables, 1) should the script run and 2) is it running already. If it shouldn’t run, then we just quit out (last else if). However if its already running, I want to delay 5 seconds (actually 30, 5 is for testing) and try again. I have a handler that reads these values from a plist. It works great. I want it to start over so it can read the values again…

I have the script below in the on run handler.

1-Can this work
2-If so, how… guessing it needs some reorg and either continue, or return statements in there, both of which I’ve not been as good at as I should…

The “testing” variable is a property… so I can test this… without the ‘tell me to quit’ throwing an error. I’m actually not sure whether I need that for a non-Stay Open app but its there…

Thanks, all…

if ((shouldScriptRun) and (scriptRunning = false)) then --   this means ready to run
	
	tell application docLoaderPath
		activate
	end tell
	if (testing = false) then tell me to quit
	
	--if its already running
else if (shouldScriptRun) and (scriptRunning) then
	
	delay 5
	run script file thisScript
	
	--doesn't matter if its running, it shouldn't either way gets possiblity 3 and 4
else if (shouldScriptRun = false) then
	if (testing = false) then tell me to quit
end if

(Lenny Eiger) #2

I figured out another way to do this, within the context another handler. It works, but my question still remains - altho’ its a curiosity now and not a panicked call for help.
Thanks, Lenny


(Nigel Garvey) #3

It’s difficult to assess the situation without knowing more about what happens in the rest of the script. It may be preferable to have the current script as a stay-open app with an idle handler. Or instead of ‘run script file thisScript’, you might use ‘tell me to run’ or ‘run me’. If the script has any properties, retriggering it from the script file starts with them set to the values currently in the file, which are only updated after the script actually quits, whereas retriggering the running script itself retains any changes made in the current run.