help please: wait for window to be active

Stefan, what if you didn’t know the exact window title but it contained at least “Process Extracted Parts.”

That TG tools window on mac at least says " Process Extracted Parts 3.32 " (with a space in the beginning and end along with a very specific version number). I want to wait until it’s active but not sure with a name that is ambiguous.

You can also specify partial strings


repeat until exists (1st window whose title contains "Extracted")
	delay 0.2
end repeat

I downloaded the demo version of Finale but I am unable to use it correctly so I will just post a piece of code which I didn’t tested.

property finaleProcess : "Finale 2014"

on win_wait_active(theObjectID)
	tell application "System Events" to tell process finaleProcess
		repeat until exists (first window whose name starts with "Process Extracted Parts")
			delay 0.2
		end repeat
	end tell
end win_wait_active

Yvan KOENIG running Yosemite 10.10.4 (VALLAURIS, France) lundi 13 juillet 2015 21:38:08

Oops, Stefan was posting while I was writing.

PS: I never use those convenience handlers.
Timing and referencing of GUI scripting is crucial anyway, so avoid any “chaining”.

I’m using a lot of “ partially long “ GUI scripts in Finale, all are written straight even if there are code repetitions.

Thanks, guys.

What do you mean by convenience handlers, Stefan? You mean like having helper functions? Like having a separate file that contains the methods/functions win_wait_active, etc.?

exactly

Is most of the performance loss referencing the other helper script or is it mainly lost another way…?

I would assume it is mostly to do with when you do :

tell something to
tell something to
tell something to
do something
do something else
do something different
do something again
end tell
end tell
end tell

writing it out longways that way. however when I write

do_something_else_with_helper()
do_something_different_with_helper()
do_something_again_with_helper()
do_something_with_helper()

it looks shorter and is faster to write but in reality, the script must do something like this (as well as communicating with another file)

tell something to
tell something to
tell something to
do something
end tell
end tell
end tell

tell something to
tell something to
tell something to
do something different
end tell
end tell
end tell

tell something to
tell something to
tell something to
do something else
end tell
end tell
end tell

tell something to
tell something to
tell something to
do something again
end tell
end tell
end tell

It’s not a performance issue, I’m just speaking from experience: write code as straight as possible.
Any splitting code into handlers, separate scripts etc. is more error-prone to break the UI responding chain.

The shortest code is not always the most effective

actually am I missing something to this because it hangs up and says “The variable title is not defined.”

of course you have to use that snippet in an System Events and process tell block

property finaleProcess : "Finale 2014"

tell application "System Events"
	tell process finaleProcess
		-- click a menu item or do something else to open a window
		repeat until exists (1st window whose title contains "Extracted")
			delay 0.2
		end repeat
	end tell
end tell

derp… my bad