No internet connection
  1. Home
  2. How to

How do you check if a menu item exists?

By Chad Wahlbrink @Chad2021-09-27 15:17:40.733Z

I have been working on this script to toggle between Tidal and Pro Tools playback. Currently, one of them needs to be playing in order to get it to work since I don't know how I would check if Tidal is playing.

In Tidal, the Playback menu switches between having "Play" and "Pause" as menu items. Is there an easy way to check if a menu item exists?

For instance, If "Play" exists in Tidal, I want to click it.

Solved in post #2, click to view
  • 3 replies
  1. Here you go:

    const tidalApp = sf.ui.app('com.tidal.desktop')
    
    // Determine if Play or Pause exists in Playback menu
    // This uses a ternary operator: If "Playback" exists then it will return "Play" otherwise it returns "Pause"
    var playOrPause = (tidalApp.getMenuItem("Playback", "Play").exists) ? "Play" : "Pause";
    
    tidalApp.menuClick({
        menuPath: ["Playback",playOrPause]
        });
    
    Reply1 LikeSolution
    1. This assumes, of course, that Tidal is already open.

      1. Chad Wahlbrink @Chad2021-09-27 18:54:33.054Z

        This is great @Chris_Shaw ! Thanks for the help.

        Here's what I have going now:

        
        const tidalApp = sf.ui.app('com.tidal.desktop')
        
        // Determine if Play or Pause exists in Playback menu
        // This uses a ternary operator: If "Playback" exists then it will return "Play" otherwise it returns "Pause"
        // ↓ Thanks to Chris Shaw for this ↓
        
        var playOrPause = (tidalApp.getMenuItem("Playback", "Play").exists) ? "Play" : "Pause";
        
        
        if (sf.ui.proTools.isPlaying) {
        
            // Stop Pro Tools and Play Tidal
        
            sf.ui.proTools.mainWindow.transportViewCluster.transportButtons.stopButton.elementClick();
            tidalApp.menuClick({
                menuPath: ["Playback", "Play"]
            })
        
        } else if (playOrPause == "Play") {
        
            // Play Tidal if neither is playing
        
            tidalApp.menuClick({
                menuPath: ["Playback", "Play"]
            })
        
        } else {
        
            // Pause Tidal and Play Pro Tools
        
            tidalApp.menuClick({
                menuPath: ["Playback", "Pause"]
            })
            sf.ui.proTools.mainWindow.transportViewCluster.transportButtons.playButton.elementClick();
        }