"exists entire contents of first UI element" - doesn't work

I’m trying to get this script to work (on Mavericks), with no success, the script stays in the loop forever:

launch application "iTunes"
set launchCompleted to false

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

What I want to achieve is for an applescript to continue only if an app (for example iTunes) has finished loading.
From what I understand “exists entire contents of first UI element” is the way to go - but it doesn’t work…

Hi,

this might be more reasonable


launch application "iTunes"

repeat while application "iTunes" is not running
	delay 0.2
end repeat

Stefan,

the problem with that is that it doesn’t wait until the application has finished launching/loading.
I’m using Sibelius 7 and it takes app. 10 seconds until Sibelius has finished loading/launching and I don’t want the AppleScript to continue until those X seconds has completed.

launch application "Sibelius 7"

repeat while application "Sibelius 7" is not running
	delay 0.2
end repeat

say "now"

use Finale ! :wink:

then I’d check for one specific UI element instead of entire contents

actually I’m in the process of going FROM Finale to Sibelius.:wink:

Sibelius is unfortunately not AppleScript:able - I’ve never worked with UI elements in AS, could you give me an code example of how it might look like?

for example, this script doesn’t leave the loop:

launch application "Sibelius 7"
set launchCompleted to false

repeat while (not launchCompleted)
	tell application "System Events"
		tell process "Sibelius 7"
			set launchCompleted to (exists entire contents of first menu bar)
		end tell
	end tell
end repeat

say "now"

In other situations as well, it would be good to be able to halt an AS until one application has finished launching/loading…

I’m working with Finale for more than 20 years. I don’t like to switch to Sibelius although Sibelius might be the better choice meanwhile.

For example check for the existence of the first window


tell application "System Events"
	tell process "Sibelius"
		set launchCompleted to (exists window 1)
	end tell
end tell

I’m “fortunate” not being very good in Finale, maybe that helps the switch.

“(exists window 1)” doesn’t work since the Sibelius opening window (before it has finished launching) trigs it.

launch application "Sibelius 7"
set launchCompleted to false

repeat while (not launchCompleted)
	tell application "System Events"
		tell process "Sibelius 7"
			set launchCompleted to (exists window 1)
		end tell
	end tell
end repeat

say "now"

this works in Finale


launch application "Finale 2014"
set launchCompleted to false

repeat while (not launchCompleted)
	tell application "System Events"
		tell process "Finale 2014"
			set launchCompleted to (exists menu 1 of menu bar 1)
		end tell
	end tell
end repeat

say "now"

hm, not in Sibelius 7 - still, the opening window trigs it…

this works too


tell application "Finale 2014"
	launch
	activate
end tell

say "now"

normally the activate command waits until the application has finished loading

not with Sibelius…


launch application "Sibelius 7"
set launchCompleted to false

repeat while (not launchCompleted)
	tell application "System Events"
		tell process "Sibelius 7"
			set launchCompleted to (exists menu 1 of menu bar 1)
		end tell
	end tell
end repeat

say "now"

I guess this SHOULD work… - Sibelius is acting strangely here…

Is there another UI element one could try?

funny, for some reason this works:

launch application "Sibelius 7"
set launchCompleted to false

repeat while (not launchCompleted)
	tell application "System Events"
		tell process "Sibelius 7"
			set launchCompleted to (exists third UI element)
		end tell
	end tell
end repeat

say "now"