I have one applescript that must be executed in 3 cases:
Active App Did Change
Focused Window or Window Title Did Change
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".
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.