Active App or Focused Window or Window Title Did Change

I have one applescript that must be executed in 3 cases:

  1. Active App Did Change
  2. Focused Window or Window Title Did Change
  3. Active App Did Change and Focused Window or Window Title Did Change

The applescript is correctly executed in the first case: active app did change but focused window and window title didn't change. This occurs when two apps have no windows opened. As example, if I switch from Finder without windows to TextEdit without windows, the applescript is executed correctly.

The applescript is correctly executed also in the second case: focused window or window title did change. This occurs when I change from window to window inside the same app.

The applescript is correctly executed SOMETIMES in the third case, when I change between apps with different windows. But sometimes is not executed correctly. I guess that the problem is the applescript is executed twice.

I would like to ask how to execute the applescript once when the app did change and the window did change at the same time (the third case).

It would also be great to have a new trigger that mix both triggers. I mean to add a new trigger called "Active App or Focused Window or Window Title Did Change".

@jordikt could you please share the AppleScript and your BTT config? That way, I can take a look.

1 Like

If the issue is caused by multi execution, you could either add a variable to your script that checks when it was last run. Or create some debouncing logic.

In BTT this can be done using the predefined actions
"Execute Action Sequence After Timeout / Delay (Cancellable)"
and
"Cancel Timed Action Sequence"

Basically you'd always first cancel any existing cancellable timed action sequence, and then start a new one after a small delay.

That might be a good idea, I'll check!

1 Like

I will wait for that. If you can implement that new trigger, my problem is resolved.

If you can't/don't implement it, I will try your suggestions.

Thanks!

Thanks for your help @fortred2!

I will send you the files if the new trigger it's not implemented.

1 Like

It works like a charm!!!

And it's very easy to configure!!

Thanks a lot for your help!!