reaper.Undo_BeginBlock()
reaper.PreventUIRefresh(1)
local sws = reaper.GetToggleCommandState(reaper.NamedCommandLookup("_SWS_TOGZOOMHORIZ_ITEMS"))
if sws == 0 then
local _,_,sectionID,cmdID,_,_,_ = reaper.get_action_context()
reaper.SetToggleCommandState(sectionID, cmdID, 1)
reaper.RefreshToolbar2(sectionID, cmdID)
reaper.Main_OnCommand(reaper.NamedCommandLookup("_SWS_SAVEALLSELITEMS1"),0) --save items
reaper.Main_OnCommand(40182,0)
reaper.Main_OnCommand(reaper.NamedCommandLookup("_SWS_TOGZOOMHORIZ_ITEMS"),0)
reaper.Main_OnCommand(reaper.NamedCommandLookup("_SWS_RESTALLSELITEMS1"),0) --restore items
elseif sws == 1 then
local _,_,sectionID,cmdID,_,_,_ = reaper.get_action_context()
reaper.SetToggleCommandState(sectionID, cmdID, 0)
reaper.RefreshToolbar2(sectionID, cmdID)
reaper.Main_OnCommand(reaper.NamedCommandLookup("_SWS_SAVEALLSELITEMS1"),0) --save items
reaper.Main_OnCommand(40182,0)
reaper.Main_OnCommand(reaper.NamedCommandLookup("_SWS_TOGZOOMHORIZ_ITEMS"),0)
reaper.Main_OnCommand(reaper.NamedCommandLookup("_SWS_RESTALLSELITEMS1"),0) --restore items
end
reaper.Undo_EndBlock('Toggle zoom all tracks', -1)
reaper.PreventUIRefresh(-1)