Automation scripts help you perform repetitive tasks quickly and consistently. These examples demonstrate common automation scenarios based on Aseprite’s actual test suite.
This script automatically adds an outline to the current sprite’s content:
-- Add outline to the active spritelocal sprite = app.activeSpriteif not sprite then print("No active sprite") returnend-- Define outline colorlocal outlineColor = Color(0, 0, 0) -- Black outline-- Apply outline commandapp.command.Outline{ color = outlineColor, matrix = 'circle', -- or 'square' place = 'outside' -- 'inside' or 'outside'}print("Outline added successfully")
-- Resize sprite to specific dimensionslocal sprite = app.activeSpriteif not sprite then return app.alert("No sprite is active")endlocal targetWidth = 64local targetHeight = 64sprite:resize(targetWidth, targetHeight)print("Resized to " .. targetWidth .. "x" .. targetHeight)
Automatically crop sprites to the current selection:
local sprite = app.activeSpriteif not sprite then return app.alert("No active sprite")endif sprite.selection.isEmpty then return app.alert("No selection")end-- Crop to selectionapp.command.CropSprite()print("Cropped to selection")
local sprite = app.activeSpriteif not sprite then return app.alert("No active sprite")end-- Store original sizelocal originalWidth = sprite.widthlocal originalHeight = sprite.height-- Trim the spriteapp.command.AutocropSprite()local newWidth = sprite.widthlocal newHeight = sprite.heightprint(string.format("Trimmed from %dx%d to %dx%d", originalWidth, originalHeight, newWidth, newHeight))
local sprite = app.activeSpriteif not sprite then return app.alert("No active sprite")endlocal layerCount = #sprite.layers-- Flatten all layerssprite:flatten()print("Flattened " .. layerCount .. " layers into one")
local sprite = app.activeSpriteif not sprite then return app.alert("No active sprite")end-- Create a layer for frame numberslocal numberLayer = sprite:newLayer()numberLayer.name = "Frame Numbers"local textColor = Color(255, 255, 255)for i, frame in ipairs(sprite.frames) do app.activeFrame = frame -- Draw frame number (simple implementation) -- In practice, you'd use a text rendering library or pre-made number sprites local cel = sprite:newCel(numberLayer, frame) print("Frame " .. i)endprint("Added frame numbers")
local sprite = app.activeSpriteif not sprite then return app.alert("No active sprite")end-- Save current framelocal originalFrame = app.activeFrame-- Apply brightness to all framesfor i, frame in ipairs(sprite.frames) do app.activeFrame = frame app.command.BrightnessContrast{ brightness = 25, contrast = 10 } print("Processed frame " .. i)end-- Restore original frameapp.activeFrame = originalFrameprint("Applied adjustments to " .. #sprite.frames .. " frames")
local sprite = app.activeSpriteif not sprite then return app.alert("No active sprite")endlocal fromColor = Color(255, 0, 0) -- Redlocal toColor = Color(0, 0, 255) -- Blue-- Replace color using commandapp.command.ReplaceColor{ from = fromColor, to = toColor}print("Replaced red with blue")
local sprite = app.activeSpriteif not sprite then return app.alert("No active sprite")end-- Select all red-ish colorslocal targetColor = Color(255, 0, 0)local tolerance = 32app.command.MaskByColor{ color = targetColor, tolerance = tolerance}print("Selected colors similar to red")
local sprite = app.activeSpriteif not sprite then return app.alert("No active sprite")endif sprite.selection.isEmpty then return app.alert("Make a selection first")end-- Apply blur filterapp.command.ConvolutionMatrix{ fromResource = "blur-3x3"}print("Applied blur to selection")
local sprite = app.activeSpriteif not sprite then return app.alert("No active sprite")end-- Invert all colorsapp.command.InvertColor()print("Inverted colors")
local sprite = app.activeSpriteif not sprite then return app.alert("No active sprite")end-- Shift hue by 60 degreesapp.command.HueSaturation{ hue = 60, saturation = 0, value = 0}print("Shifted hue by 60 degrees")
local sprite = app.activeSpriteif not sprite then return app.alert("No active sprite")endif sprite.colorMode ~= ColorMode.INDEXED then -- Convert to indexed to extract palette app.command.ChangePixelFormat{ format="indexed" }endlocal palette = sprite.palettes[1]print("Palette has " .. #palette .. " colors")for i = 0, #palette - 1 do local color = palette:getColor(i) print(string.format("Color %d: RGB(%d, %d, %d)", i, color.red, color.green, color.blue))end
local sprite = app.activeSpriteif not sprite then return app.alert("No active sprite")endlocal baseName = sprite.filename or "sprite"baseName = app.fs.fileTitle(baseName)for i, layer in ipairs(sprite.layers) do -- Hide all layers for _, l in ipairs(sprite.layers) do l.isVisible = false end -- Show only current layer layer.isVisible = true -- Export local filename = baseName .. "_" .. layer.name .. ".png" sprite:saveCopyAs(filename) print("Exported: " .. filename)end-- Show all layers againfor _, l in ipairs(sprite.layers) do l.isVisible = trueendprint("Exported " .. #sprite.layers .. " layers")