Export to multiple files: Each layer and frames

Asume a file with five layers, each layer has ten frames. now i want to export every frame from every layer into separate files. each file should be named by the respective layer name followed by the frame number.
I could do this manually: save as png, make top layer invisible → export as png, make top layer invisible…

Is there a way to automate this process?

you coulkd probably do via a script, but why do you need this? if your workflow needs every frame of every layer to be a different file i think theres something wrong with your process.

like you are genuinely giving me “Your scientists were so preoccupied with whether or not they could, they didn’t stop to think if they should.” vibes.

I managed to create a script which does what i need, if somebody else is interested:

local sprite = app.activeSprite
if not sprite then
    app.alert("No active sprite!")
    return
end

-- Determine the output folder based on the sprite's file path
local basePath = sprite.filename
if basePath == "" then
    app.alert("Please save the sprite file first.")
    return
end

local baseDir = app.fs.filePath(basePath)
local baseName = app.fs.fileTitle(basePath)
local outputFolder = app.fs.joinPath(baseDir, baseName)
app.fs.makeDirectory(outputFolder) -- Ensure the folder exists

local dlg = Dialog("Export Frames by Layers")
dlg:separator()
dlg:button{
    text = "OK",
    onclick = function()
        for i, layer in ipairs(sprite.layers) do
            if layer.isGroup then
                goto continue -- Skip groups
            end

            -- Hide all layers except the current one
            for _, l in ipairs(sprite.layers) do
                l.isVisible = (l == layer)
            end

            local filename = string.format("%s.png", layer.name)
            local filepath = app.fs.joinPath(outputFolder, filename)

            -- Export frames
            app.command.SaveFileCopyAs { ui = false, filename = filepath }

            ::continue::
        end

        app.alert("Export complete! Files saved to: " .. outputFolder)
        dlg:close()
    end
}
dlg:button{text = "Cancel"}
dlg:show()