Search code examples
macososascriptjavascript-automation

Bring window of process to the front?


This should be a simple enough question to answer (I assume).

Say I want to activate window 1 of process "ScreenFlow", how would I do this?

I do know that Application('ScreenFlow').activate() brings Processes['ScreenFlow').windows[0] to the front. But how then to switch to Processes['ScreenFlow').windows[n]?

Thanks


Solution

  • The action required to do this job is AXRaise:

    function setWinFront(n) {
        var system = Application('System Events')
        var ScreenFlow = system.processes['ScreenFlow']
        Screenflow.windows[n].actions['AXRaise'].perform()
    }
    

    In the future when wanting to perform any changes such as this it maybe wise to look in process.windows[1].actions() to see if actions exist, and if they do - try them first.

    Alternatively one can also look in the object's attributes using process.windows[1].attributes()