I need to consistently focus on the first window of an app, since it has two open and their names change thus wondering if this is possible, without navigating through the apps menu?
Currently the below doesn't work if the second window was previously active (over the main window), as they need to be triggered always in the first window.
tell application "System Events" to tell application process "Microsoft Teams"
set frontmost to true
key code 44 using {command down}
keystroke "dnd"
key code 76
end tell
EDIT: AXRaise of first (or last) window doesn't seem to work neither as it is just the first in the list which changes according to which window was the last active from what I understand. Hopefully there is another way?
perform action "AXRaise" of first window of process "Microsoft Teams"
FYI - I was also looking for a solution for the opposite targeting the last (second) window but couldn't find a solution without using the menu (or dock menu).
EDIT: as user3439894 suggested I may be able to use different properties attribute if window id is not provided. The only differentiator I see is the title in the below list where the first window always seems to end with "| Microsoft Teams [QSP]"
{
{minimum value:missing value, orientation:missing value, position:{4088, 45}, class:window, accessibility description:missing value, role description:"standard window", focused:false, title:"testing | Microsoft Teams", size:{1350, 844}, help:missing value, entire contents:{}, enabled:missing value, maximum value:missing value, role:"AXWindow", value:missing value, subrole:"AXStandardWindow", selected:missing value, name:"testing | Microsoft Teams", description:"standard window"},
{minimum value:missing value, orientation:missing value, position:{4068, 25}, class:window, accessibility description:missing value, role description:"standard window", focused:false, title:"Calendar | Microsoft Teams [QSP]", size:{1095, 645}, help:missing value, entire contents:{}, enabled:missing value, maximum value:missing value, role:"AXWindow", value:missing value, subrole:"AXStandardWindow", selected:missing value, name:"Calendar | Microsoft Teams [QSP]", description:"standard window"}
}
tell application "System Events" to tell application process "Microsoft Teams" to get the properties of every window
and updated the OP's, anything we can use as per your suggestion? – Markus Oct 15 '21 at 11:17