How can I detect currently active window in Apple MacOS?

0

Recently, this started happening.

I need very fast switch sorting my notes between "Date Edit" and "Title" so I lot pressing key "cmd+," then "arrow down", choose with "enter", and "escape". Now that window open but it hasn't focus and I cannot switch setting with keyboard only. Combination with "tab" doesn't work too - cycle control with "tab" or switch from some hidden window with "cmd+tab" or "alt+tab". I have closed all applications so there is no interference with others.

So it came to mind - catch object who has that focus.

How can I detect currently active window in Apple MacOS ?

BG Bruno

Posted 2017-04-02T18:17:07.767

Reputation: 635

In which application are your notes in? I can't find the ability to sort notes in macOS' Notes.app. – oa- – 2017-04-06T11:22:04.553

@oa #notes.app provide sorting in setting "Notes / Preferences / Sort notes by" – BG Bruno – 2017-04-06T12:18:10.710

Answers

0

I've found a solution. Change "mySort" accordingly:

set sort1 to "Date Edited"
set sort2 to "Date Created"
set sort3 to "Title"

set mySort to sort1

tell application "System Events"
    tell application process "Notes"
        set frontmost to true
        keystroke "," using command down
        delay 1
        tell window "Preferences"
            #click static text "Sort notes by:" of group 1
            #set winstuff to entire contents of every group
            delay 0.5
            click pop up button 3 of group 1 of window "Preferences" of application process "Notes" of application "System Events"
            delay 0.1
            click menu item mySort of menu 1 of pop up button 3 of group 1 of window "Preferences" of application process "Notes" of application "System Events"
            delay 0.1

            keystroke "w" using command down
        end tell
    end tell
end tell

oa-

Posted 2017-04-02T18:17:07.767

Reputation: 378

Nice script @oa thank you - but Q1 how can I run it? - and still does not answer the origin question Q2 How can I detect currently active window? :-) – BG Bruno – 2017-04-07T22:38:35.017