Check if application launch has finished

Hi to all!

In my script I want to launch two apps one after another by a simple

tell application "app1" to launch
tell application "app2" to launch

But as the first app takes more time to launch, if have to wait until it has finished launching, before i can fire up the second one. How can I test if the launch has completed?

TIA

If you dont need app1 open to launch app2, you might try

ignoring application responses
	launch application "app1"
	launch application "app2"
end ignoring

If app1’s being launched is important to the launching of app2, you might try

launch application "app1"

with timeout of 30 seconds
	repeat until running of application "app1"
	end repeat
end timeout

launch application "app2"

Hi mik!

Thanks for your suggestions! The second one is the one I am searching for. Unfortunately it doesn’t work. Still both apps are being launched immediately. I tried it with Photoshop (#1) and Textedit (#2), as Photoshop takes a very long time until it has finished.

This seemed to keep Mail from opening until Excel was loaded. Perhaps a similar workaround could be fashioned for your app1.

set firstApplication to "Microsoft Excel"
set secondApplication to "Mail"

launch application firstApplication

set testName to ""
set checkName to "x"

repeat until testName = checkName
	try
		set testName to name of window 1 of application firstApplication
		set checkName to name of window 1 of application firstApplication
	end try
end repeat

launch application secondApplication

Well, it assumes that app 1 opens a window. I tried the script exactly as you posted it, but my Excel starts window-less and therefore the script can’t set “testName”.

I finally found a solution:

set firstApplication to "Microsoft Excel"
set secondApplication to "TextEdit"

launch application firstApplication

set z to false

repeat while (not z)
	tell application "System Events"
		tell process firstApplication
			set z to (exists entire contents of first UI element)
		end tell
	end tell
end repeat

launch application secondApplication

It even works with apps that have no windows and reside in the menu only, like ShoveBox, Butler etc.

I’m guesing that my sucess testing for a window depended on using Excel2004 and/or having a Personal Macro Workbook. In Excel 2008, that would cause an issue.

UI element sounds like most apps will have one.