Wait until app finishes launching

I am trying to get my app to launch Adobe InDesign CS2, but wait for it to finish launching before it moves to the next step. But it gets ahead of itself and errors out.

Any idea how to halt my script until it finishes launching fully?

Thanks!

Hi

maybe a “delay 15” or “delay 20” seconds, this will depend on how quick it takes your Mac to launch ID.

Budgie

Hi,

“random” delays are always unreliable.
A better way is to wait for a certain UI element like a window or a palette

StefanK, Good idea!

I’m looking thru InDesign’s AS library but I’m not sure how I should go about scripting it.
I’m thinking that the best solution would be to use the Tools palette but I dont know how to see if that palette has been loaded.

Any suggestions?

I don’t have the App, but the way I normally do this is to write a brief script to look at the open windows after a fresh start of the app. Then knowing how to identify the window, in a repeat until loop with a short delay in it, I hang in the loop until that window appears then drop out of the loop and press on.

Maybe do a repeat with a try to get something from ID, like the version number or something.
Like

set myIDActive to false
repeat while myIDActive is false
try
delay 1
tell app "adobe indesign cs2"
get version --if doesn't work then try statement jumps out and myIDActive doesn't change
set myIDActive to true
end tell
end try
end repeat

It’s kind of a dumb hack but maybe it’ll work. ??
I’d recommend having ID get started at the very beginning of the script as soon as possible

SuperMacGuy, that did it!

Thanks!

The problem with the script in post #6 is that it works only once, if at all. If the related app (in this example “InDesign”) has been started and quit previously (read: is no longer running), the system still knows the version info, thus will return ‘true’ without even (re)launching the app. This is no good unless there is a command (which I don’t know of) to immediately drop the obtained version info:

set myIDActive to false
repeat while myIDActive is false
	try
		delay 1
		tell application "adobe indesign cs2"
			get version --if doesn't work then try statement jumps out and myIDActive doesn't change
			set myIDActive to true
			-- forget/drop the version info here
		end tell
	end try
end repeat

So try some property like “active document”.

But this begs the question: why do you need a delay?

I always do:
Tell Application “Indesign CS2” to launch
at the beginning of the script so it will start launching in the background. THen do all of your other startup steps. Then when you need Indesign, do:

Tell Application “Indesign CS2”
Activate
–rest of script

The activate will wait until the app is responding (i.e. it is finished launching).