No internet connection
  1. Home
  2. How to

Toggle Avid Control Desktop Visibility

By TJ Allen @TJ_Allen
    2024-11-09 13:57:23.053Z

    Hi all,

    The new Eucon update has brought some brilliant new features, and being able to have the Avid Control Desktop persist at the front is one of them. I've got a script I've cobbled together to toggle its visibility, but I can't for the life of me get it to automatically return window focus to Pro Tools after making it visible. If anyone with a better scripting brain can help me out, I'd be eternally grateful!

    Here's what I've got.

    const appName = 'Avid Control Desktop';
    const appRef = sf.ui.app('com.Avid.AvidControl');
    const appPath = '/Applications/Avid Control Desktop.app';
    
    const isAppRunning = appRef.isRunning;
    const isAppFrontmost = sf.ui.frontmostApp.uiElement['Title'] === appName;
    const isAppWindowOpen = appRef.windows.length > 0;
    
    switch (true) {
        case (!isAppRunning):
            sf.app.launch({ path: appPath });
            break
        case (!isAppFrontmost && isAppWindowOpen):
            sf.app.launch({ path: appPath });
    
            break
      
        case (!isAppFrontmost):
            sf.app.launch({ path: appPath });
            
            break
        case (isAppFrontmost && isAppWindowOpen):
            appRef.menuClick({
                menuPath: [appName, `Hide ${appName}`],
            });
            break
    }
    
    

    It works, but it'd be great to have it automatically return focus to Pro Tools after showing the Control App. As it stands, I have to double press to hide it again when Pro Tools is focussed, but that I can live with!

    Many thanks,
    Tim

    Solved in post #2, click to view
    • 5 replies
    1. Chris Shaw @Chris_Shaw2024-11-09 23:00:48.963Z2024-11-09 23:42:49.290Z

      I couldn't figure out how to do this with SF / Javascript but it's relatively easy to do with AppleScript.
      I also simplified the code:

      const avidControl = sf.ui.app('com.Avid.AvidControl');
      
      // Ensure Avid Control Desktop is running
      if (!avidControl.isRunning) {
          
          // Open Avid Control Desktop
          avidControl.appEnsureIsRunning()
          sf.wait({ intervalMs: 500 })
      
          // Switch back to Pro Tools
          sf.ui.proTools.appActivateMainWindow()
          throw 0
      }
      
      // Toggle Avid Control Desktop visible state
      sf.system.execAppleScript({
         script: `tell application "System Events"
      	
      	set isHidden to visible of application process "Avid Control Desktop"
      	
      	if isHidden then
      		set visible of application process "Avid Control Desktop" to false
      	else
      		set visible of application process "Avid Control Desktop" to true
      	end if
      	
      end tell`,
      })
      
      
      Reply1 LikeSolution
      1. Chris Shaw @Chris_Shaw2024-11-09 23:03:34.183Z2024-11-09 23:32:24.770Z

        The advantage to using AppleScript is that there's no need to change the focus from Pro Tools at all since it's all done with system events in the background.

        1. TTJ Allen @TJ_Allen
            2024-11-10 09:26:15.226Z

            This is brilliant - thank so much Chris. So much sleeker and more efficient. I need to spend a bit of time exploring AppleScripts for sure!

            1. Chris Shaw @Chris_Shaw2024-11-12 17:54:19.348Z2024-11-12 18:46:08.042Z

              This version is even more compact - you only need to ask AppleScript to get the visible status of Avid Control Desktop. All of the other commands can be done via SF

              const avidControl = sf.ui.app('com.Avid.AvidControl');
              
              // Ensure Avid Control Desktop is running
              if (!avidControl.isRunning) {
              
                  // Open Avid Control Desktop
                  avidControl.appEnsureIsRunning()
                  sf.wait({ intervalMs: 500 })
              
                  // Switch back to Pro Tools
                  sf.ui.proTools.appActivateMainWindow()
                  throw 0
              }
              
              //Get visible status of Avid Control Desktop
              /** @type {boolean} isAvidControlVisible */
              let isAvidControlVisible = sf.system.execAppleScript({
                  script: `tell application "System Events"
              	get visible of application process "Avid Control Desktop"
              end tell`,
              }).result
              
              // Toggle Avid Control Desktop visible state
              isAvidControlVisible ? avidControl.appHide() : avidControl.appUnhide();
              
              
              1. TTJ Allen @TJ_Allen
                  2024-11-13 11:36:29.646Z

                  Works a treat and really extends the functionality of the new Eucon features. Thanks Chris.