[Script] Immediately name new layers

Hello there. I did some searching but couldn’t find anything like this. I tend to try and keep layers organized, but eventually succumb to the New Layer 12, New Layer 13, New Layer 14, New Layer 15, epidemic :joy:

This script makes a new layer and creates an input box to immediately name it. After typing a name you can press the okay button or just hit enter after you’re finished typing the name.

You can go into edit > keyboard shortcuts and assign a shortcut or replace the new layer shortcut to run it. Hope this helps anyone who has the same layer hygiene problem I do!

-- Select current sprite
local spr = app.activeSprite
if not spr then
  app.alert("No active sprite found.")
  return
end

-- Create new layer
local newLayer = spr:newLayer()

-- layer name dialog creation
local dlg = Dialog("New Layer")
dlg
  :label{ id="desc", text="Input a name for the new layer:" }
  :entry{ id="layerName", text="", focus=true }
  :button{ id="ok", text="OK", focus=true }
  :button{ id="cancel", text="Cancel" }
  :show()

-- input checker
if dlg.data.ok and dlg.data.layerName ~= "" then
  newLayer.name = dlg.data.layerName
else
  -- If cancelled or name is empty, delete the layer
  spr:deleteLayer(newLayer)
end

app.refresh()
2 Likes