Is there a way to populate a list of "open external editors"?

Hi, I have a script that hides “all” trackdsp external editors for the track i’m on.
but sometimes i’m not on the track i opened the external editors at.
so how would i go about modifying this to close only the external editors that are open?

renoise.tool():add_keybinding{name="Global:Paketti:Hide Track DSP Devices",invoke=function()
  if table.count(renoise.song().selected_track.devices) >1 then
     for i=2,(table.count(renoise.song().selected_track.devices)) do 
      if renoise.song().selected_track.devices[i].external_editor_available==true
       then
       renoise.song().selected_track.devices[i].external_editor_visible=false
      end
     end
  end
end}