New Action: "Wait for app to open"

It would be great if a new "Wait for app to open" action is added as currently i just use delays to do this. Sometimes its not reliable as the app occasionally opens too slow, and the keyboard shortcuts are inserted in to the wrong app instead.

Thanks again for supporting my requests for AQT @Andreas_Hegenberg!

Hell yes that would be so awesome :heart_eyes::heart_eyes:

The problem is that there are two things:
1.) When is an app completely launched according to macOS
2.) When is the app really able to accept input (internal app state)

The first one is easy to figure out, however the second one is not. That's why I'm not sure whether this would really be helpful, but I will do some experiments with, maybe I can find some sort of heuristic do determine whether an app is ready.

2 Likes

It should be helpful in making these things a little bit more stable though, e.g. we can use a static delay after a wait for app,

@Andreas_Hegenberg

I tried to get around this by including an applescript that would run the necessary delay:

repeat until application "Microsoft OneNote" is running
delay 0.5
end repeat

However, all the actions below continue to run regardless of whether the script above has finished. The script is set to blocking.

Can BTT prevent actions from being executed until an applescript has finished?

wait, couldn't you do

if application "OneNote" is running
delay 0.5
--trigger BTT action
end if

Apologies, I meant the actions within the BTT workflow, not the script.

I decided instead to just incorporate all the actions into an applescript instead, so it all worked nicely with each other:

@yuuiko couldn't you use the "send keyboard shortcut to a specific app" command? Regarding your opening post.

Still totally in for a "wait for app to open" since not keyboard related commands are kinda missing for now! :slightly_smiling_face:

Yeah one of my users pointed that out, I never realise we had an action like that ahaha

1 Like

Unfortunately, that action will send the keyboard input to the wrong app if the desired app isn't open when the "Send to Specific App" action triggers. This can cause undesired effects.

UPDATE: I managed to solve the problem of waiting for the application to start by using the following (blocking) Apple Script:

tell application "appName" to activate

repeat until application "appName" is running
	delay 0.1
end repeat

if application "appName" is running then
	tell application "System Events" to tell process "appName"
		repeat until (count of windows) is greater than 0
			delay 0.1
		end repeat
	end tell
end if

NOTE: make sure you change "appName" to reflect the app you wish to activate!

Follow that with the "Send Shortcut to Specific App" option, and you should have a trigger that guarantees that the app is open before sending the shortcut!