Can anyone help me modify this code so that it only selects visible Audio tracks? Works great currently to select only Audio Tracks, but includes any hidden Audio Tracks, which throws an error in my script.
let selectedAudioTracks = sf.ui.proTools.invalidate().trackGetSelectedTracks().trackHeaders.filter
(t => t.title.value.includes("Audio Track")).map(t => t.normalizedTrackName);
sf.ui.proTools.trackSelectByName({names: selectedAudioTracks, deselectOthers: true})
I've found plenty of code for selecting visible tracks, but can't seem to integrate it with pre-selected audio tracks.
Thanks for you help.
Forrester
- Chris Shaw @Chris_Shaw2023-03-02 22:23:44.553Z2023-03-02 22:59:37.165Z
This should do it:
// Get all selected track headers let allSelectedTrackHeaders = sf.ui.proTools.invalidate().trackGetSelectedTracks().trackHeaders; //Filter to get only visible audio tracks let allVisibleSelectedAudioTrackNames = allSelectedTrackHeaders.filter(t => t != null && t.title.value.endsWith("- Audio Track ")).map(t => t.normalizedTrackName); //Select only previously selected visible audio tracks sf.ui.proTools.trackSelectByName({ names: allVisibleSelectedAudioTrackNames, deselectOthers: true });
- FForrester Savell @Forrester_Savell
Thanks so much @Chris_Shaw
A follow up noob question - what's the difference between trackHeaders and trackNames? I've seen them both used to select tracks?
Chris Shaw @Chris_Shaw2023-03-02 22:59:19.235Z2023-03-02 23:08:01.371Z
A Track Header contains all of the UI / Accessibility information of a selected track (buttons, labels, track type, dimensions and position of each track element, etc). Track names are just that - track names.
The track header information generally looks something like this:
"{\"title\":\"Leslie EG 57 - Audio Track \",\"role\":\"AXGroup\",\"fullRole\":\"AXGroup\"}"
As you can see the title not only contains the track name but also the track type.
Track headers can only be obtained from visible tracks which is why your original script would throw an error. If you try to grab the header of a hidden track the command returns
null
.
The first command returns an array of track headers for the selected tracks (which will includenull
for every hidden track) and puts that array inallSelectedTrackHeaders
The second command looks at every entry inallSelectedTrackHeaders
and returns only those headers that aren'tnull
and whosetitle
ends with"- Audio Track "
then takes those entries and returns the normalized track name (the track title without the track type) and stores the results inallVisibleSelectedAudioTrackName
.
- In reply toChris_Shaw⬆:
Chris Shaw @Chris_Shaw2023-03-02 22:34:24.910Z
re-edited the code above to make it slightly faster
Chris Shaw @Chris_Shaw2023-03-02 22:34:49.037Z
(three steps instead of four).