No internet connection
  1. Home
  2. How to

How to set an app frontmost?

By @anon6770933309
    2018-09-17 08:05:33.465Z

    If I want to set an app like Pro Tools frontmost I can use this little AppleScript code:

    sf.system.execAppleScript({
        script: 'tell application "System Events" to tell process "Pro Tools"\n' +
        'set frontmost to true\n' +
        'end tell'
    });
    

    I know about

    sf.ui.proTools.appActivateMainWindow();
    

    but this does not put the app PT frontmost but the app and one of its main windows (Edit or Mix, depending which one resides on a higher level).
    Sometimes I do not want to have one of the main windows frontmost, like for scripts that address plug-in windows (AudioSuite, Insert, VI).

    Is there an equivalent method to the AppleScript method in SF to do the same with JavaScript?

    • 3 replies
    1. The awkward but simple way to do it would be to call the appActivateMainWindow() followed by an elementRaise() call on the window you'd like focused/frontmost.

      So for instance ("raising" aka putting front most, the first audio suite window):

      sf.ui.proTools.appActivateMainWindow();
      sf.ui.proTools.floatingWindows.whoseTitle.contains('Audio Suite:').first.elementRaise();
      

      If you need something more granular we should look into creating a new separate action specifically for this.

      1. ?@anon6770933309
          2018-09-18 07:50:26.696Z

          Well, when I came up with this question I was working on a script that loads the next/previous setting in an open AudioSuite, Insert or VI plug-in depending on whatever plug-in is frontmost.
          When I tested this script via Run Command (⌘ return) it set PT’s main window frontmost which was not what I was looking for.
          If you hide PT with two plug-in windows open (e.g. 1 Audio Suite and 1 Insert) and set it frontmost again it should present the windows in the same order before hiding.

          sf.ui.proTools.appActivateMainWindow(); 
          

          doesn't do this, it sets one of the main windows (Edit or Mix) frontmost but the PI window that was frontmost before hiding.

          And

          elementRaise(); 
          

          wouldn’t help either as the script doesn’t know which sort of PI window was frontmost before hiding.
          I can live with the AppleScript solution but a dedicated SF action would be awesome. 😉

          1. Gotcha, I understand. Thanks for explaining. I'll test it against the Apple Script version to make sure we retain the same functionality.