Save / Export all XRNI from XRNS?

This is a tool that I wrote myself for this (you can try it yourself). However, I do not publish the packaged tool because I suppose that it will be necessary to attend to cases where the process takes too long (more than 10 seconds), where there are many instruments loaded with samples and so on … If there are few samples, it will not exceed 10 seconds and it will work perfectly. Otherwise, it will be necessary to use coroutines for the iteration.

local rna=renoise.app()
local rnt=renoise.tool()
local function save_all_xrni()
  local path_folder=""
  local song=renoise.song()
  local sii=song.selected_instrument_index
  --save all
  local function save_all_ins()
    if rnt:has_timer(save_all_ins) then
      rnt:remove_timer(save_all_ins)
    end
    song.selected_instrument_index=1
    for ins=1,#song.instruments do
      local filename=("%s%.3d-%.2X-%s"):format(path_folder,ins,ins-1,song:instrument(ins).name)
      rna:save_instrument(filename)
      if (song.selected_instrument_index<#song.instruments) then
        song.selected_instrument_index=song.selected_instrument_index+1
      end
    end
    song.selected_instrument_index=sii
    rna:open_path(path_folder)
    rna:show_status( "All XRNI instruments have been saved correctly.")
  end
  
  --search path
  local search_path=rna:prompt_for_path(("Select a folder to save all the instruments XRNI of the song:\n\"%s\""):format(song.name))
  if (search_path=="" or search_path=="C:\\") then
    if (string.sub( path_folder, -1 )~="\\") then
      rna:show_error("Please, reselect before a valid & existent path to save the files! No using a protected path (as \"C:\\\")")
    end
  else
    path_folder=search_path
    --print("path_folder:",path_folder)
    if not rnt:has_timer(save_all_ins) then
      rnt:add_timer(save_all_ins,500)
    end
  end
end

--register menu entry
rnt:add_menu_entry{
  name="Instrument Box:Save All Instruments As...",
  invoke=function() save_all_xrni() end
}