No internet connection
  1. Home
  2. How to

Does a track/playlist name already exist within the session

By Tristan Hoogland @Tristan
    2024-04-05 22:17:04.494Z

    Hey team, is there a way to determine if a certain playlist name already exists within the ProTools session? I'm not talking about a visible track name, obviously that's easy to get, but determining whether a playlist name deep within the session seems a little more ambitious.

    My reason being that on some very, very rare occasions I'll go to rename a track and sometimes I'll be alerted that the dialog that the track/playlist name already exists. I have a decent workaround to effectively rename the new playlist, but that requires the handling of multiple dialogs, which isn't super efficient.

    Solved in post #3, click to view
    • 6 replies
    1. Hey @Tristan ! Unfortunately, no :(
      I had hopes that we could fetch them using the PT SDK (sf.app.proTools.tracks), but it only gives us playlist names if they are expanded in the Edit window, which wouldn't work for your purposes since you'd have to have every playlist in the session showing.

      1. In reply toTristan:
        Chris Shaw @Chris_Shaw2024-04-06 18:28:28.811Z2024-04-06 19:17:03.592Z

        This won't tell you what track the playlist is on but it will tell you if a playlist name exists by checking against existing track names and alt playlists.


        There is one caveat: you will get an error if the first track of a track type being checked in the session is hidden. But it shouldn't be that hard to check it and make it visible and hide it again at the end of the script

        const playlistNameToCheck = "Audio 10"
        
        sf.ui.proTools.appActivateMainWindow();
        sf.ui.proTools.mainWindow.invalidate();
        
        let allPlaylistNames = [];
        
        // Get track names
        const tracks = sf.app.proTools.tracks.invalidate().allItems;
        
        const trackNames = tracks.map(track => track.name)
        
        const trackTypes = ["Audio", "Midi", "Instrument"]
        
        trackTypes.forEach(type => {
            
            // Scroll first trackType track into view
            const firstTrackTypeTrack = tracks.filter(t => t.type == type)[0]
        
            if (firstTrackTypeTrack) {
                sf.ui.proTools.trackSelectByName({ names: [firstTrackTypeTrack.name] })
        
                sf.ui.proTools.selectedTrack.trackScrollToView()
        
                // Define track playlist popup
                const playlistPopup = sf.ui.proTools.selectedTrack.popupButtons.allItems[1]
        
                // Open delete unused playlist window
                playlistPopup.popupMenuSelect({ menuPath: ["Delete Unused..."] })
        
                const deletePlaylistWin = sf.ui.proTools.windows.whoseTitle.is("Delete Unused Playlists").first;
        
                deletePlaylistWin.elementWaitFor()
        
                // Get alt playlists from delete unused window
                const listOfPlaylists = deletePlaylistWin.children.whoseTitle.is("List of playlists").first.children.whoseRole.is("AXRow").allItems;
                const playlistCells = listOfPlaylists.map(row => row.children.whoseRole.is("AXCell").first);
                const playlistNames = playlistCells.map(cell => cell.children.whoseRole.is("AXStaticText").first.value.value)
        
                // Dismiss Delete Playlists window
                deletePlaylistWin.buttons.whoseTitle.is("Cancel").first.elementClick();
        
                deletePlaylistWin.elementWaitFor({ waitForNoElement: true })
        
                //Combine all playlists 
                allPlaylistNames = [...allPlaylistNames, ...playlistNames]
            }
        })
        
        const playlistAndTrackNames = [...allPlaylistNames, ...trackNames]
        
        //log(playlistAndTrackNames)
        
        // Check if playlistNameToCheck exists
        let doesPlaylistNameExist = playlistAndTrackNames.includes(playlistNameToCheck)
        
        log(doesPlaylistNameExist)
        
        Reply1 LikeSolution
        1. Oops! had a couple of typos - should be fixed now

          1. In reply toChris_Shaw:

            EDIT: I didn't take MIDI and Instrument tracks into consideration. The code above has been edited.


            Additional caveat: If you have a single track of a track type and delete it but keep it's playlists theres no way to check against the kept playlists.
            (Ex: Deleting the sole MIDI track but keeping it's alt playlists)

            1. In reply toChris_Shaw:
              TTristan Hoogland @Tristan
                2024-04-06 22:55:09.485Z

                Ahh very clever, Chris! Hadn't considered viewing the delete unused playlist option. This alone isn't 100% what I was hoping as I had dreams of it checking every time a bounce was re-imported during a more repetitive and elaborate script. BUT I think what I'll do is run it first thing when the session is open, push them all into an array, then reference that and if it needs to remain up to date, I can just push every other subsequent imported track/clip name into that array. You know, cause you wanted to stay tuned with my big plans and all lol.

                Thanks dude!

                1. BTW - Line 50 is redundant. You can delete that but no harm done if left there.