function selectTrackByPartialName() local retval, trackName = reaper.GetUserInputs("Jump to Track", 1, "Track name:", "") if not retval or trackName == "" then return end trackName = trackName:lower() local bestMatch = nil local bestScore = -1 for i = 0, reaper.CountTracks(0) - 1 do local track = reaper.GetTrack(0, i) local _, name = reaper.GetSetMediaTrackInfo_String(track, "P_NAME", "", false) local nameLower = name:lower() local pos = nameLower:find(trackName, 1, true) if pos then local score = 0 -- Exact match gets highest score if nameLower == trackName then score = 10000 -- Match at start of name is second best elseif pos == 1 then score = 5000 - #name -- Shorter names rank higher -- Match after underscore or space (word boundary) elseif nameLower:sub(pos-1, pos-1):match("[_%s]") then score = 3000 - #name - pos else -- Other matches: prioritize by position and length score = 1000 - pos - #name end -- Boost score for group/folder tracks local flags = reaper.GetMediaTrackInfo_Value(track, "I_FOLDERDEPTH") if flags == 1 then score = score + 20000 -- Group tracks get priority end if score > bestScore then bestScore = score bestMatch = track end end end if bestMatch then reaper.SetOnlyTrackSelected(bestMatch) reaper.SetMixerScroll(bestMatch) reaper.Main_OnCommand(40913, 0) -- Scroll vertically to selected track else reaper.ShowMessageBox("Track not found", "Error", 0) end end selectTrackByPartialName()