Pro Tools Main window isFocused issue
Hi @chrscheuer,
I seem to be having a problem with the following code;
if (sf.ui.proTools.mainWindow.isFocused) {
log('Pro Tools Main Window is focused');
} else {
log('Pro Tools Main Window is not focused');
};
and...
if (sf.ui.proTools.windows.whoseTitle.startsWith('Edit: ').first.isFocused) {
log('Pro Tools Main Window is focused');
} else {
log('Pro Tools Main Window is not focused');
};
When I trigger either of them in Pro Tools main window I get the else log "Pro Tools Main Window is not focused" where I expect to get "Pro Tools Main Window is focused".
Thought I'd check to see if this was a bug or not.
Rock on
Kitch
Linked from:
- Christian Scheuer @chrscheuer2020-03-29 18:56:55.855Z
The ".isFocused" property comes from reading the AXFocused UI attribute directly from the macOS API. I bet that this may be false in some cases where other sub-elements may have focus - I think this is ultimately up to Pro Tools to report correctly.
You may get better results by instead reading the focusedWindow property's title, like so:if (sf.ui.proTools.focusedWindow.title.value.indexOf('Edit: ') === 0) { log('Main Window is focused'); } else { log('Main Window is not focused'); }
If you need this to work across more apps, you'd need to have more conditions in the code.
What's the logic you're trying to achieve?
We have other focus related properties that may also be relevant.Christian Scheuer @chrscheuer2020-03-29 18:59:06.832Z
Note that if you've pressed an Audio Suite window, the above code will report the Main Window as not focused (since it technically isn't), even though Pro Tools normal keyboard modifiers will still be active for the edit window.
So if what you need to determine has something to do with keystrokes, a different logic has to be used.
You can also use the window order to look for things - for example if all you need to do is to determine if the Mix window or Edit window is front most (has last been focused), then you can filter on that.Christian Scheuer @chrscheuer2020-03-29 19:07:01.186Z
This computes out of the Edit and Mix windows, which of those is front most (last to be focused) - even if for example an Audio Suite plugin window is actually focused:
var isEditWindowFocused = sf.ui.proTools.windows.filter(w => w.title.value.match(/^(Edit:|Mix:)/))[0].title.value.indexOf('Edit:') === 0;
Kitch Membery @Kitch2020-03-29 19:53:43.682Z
Thanks for that @chrscheuer. There are many workarounds for this one but thought it may be a bug. Your suggestion for using indexOf instead will work perfectly. :-)