-- @description RTL Auto Align
-- @author Rockettree Labs
-- @version 1.0
-- @about Snaps the start of all selected items to the nearest grid line.

local num_items = reaper.CountSelectedMediaItems(0)
if num_items == 0 then
    reaper.ShowMessageBox("Please select items to align to the grid.", "RTL Auto Align", 0)
    return
end

reaper.Undo_BeginBlock()

-- Item: Quantize item positions to grid (40148)
reaper.Main_OnCommand(40148, 0)

reaper.UpdateArrange()
reaper.Undo_EndBlock("RTL: Auto Align to Grid", -1)
