List aseprite palettes?

I want to make a script to dither using the colors in a selected palette.
I can do it manually but that doesn’t take into account palettes added or made by users.
Is there a way to add all of aseprite’s palettes to a list?

app.fs might help you some. For example, in my case, userConfigPath returns "C:\Users\User Name\AppData\Roaming\Aseprite". The palette presets I’ve saved are within the config path directory, in the “palettes” directory.

local userConfigPath <const> = app.fs.userConfigPath
local userPalettesPath <const> = app.fs.joinPath(userConfigPath, "palettes")
local palettesLocal <const> = app.fs.listFiles(userPalettesPath)
local lenPalettesLocal <const> = #palettesLocal
---@type Color[]
local aseColors <const> = {}

local i = 0
while i < lenPalettesLocal do
    i = i + 1
    local localPath <const> = palettesLocal[i]
    local fullPath <const> = app.fs.joinPath(userPalettesPath, localPath)
    local palette <const> = Palette { fromFile = fullPath }
    if palette then
        local lenPalette <const> = #palette
        local j = 0
        while j < lenPalette do
            local aseColor <const> = palette:getColor(j)
            aseColors[#aseColors + 1] = aseColor
            j = j + 1

local lenAseColors <const> = #aseColors
local sprite <const> = Sprite(256, 256)
local spritePalette <const> = sprite.palettes[1]
app.transaction("User Custom Palettes", function()
    local k = 0
    while k < lenAseColors do
        spritePalette:setColor(k, aseColors[1 + k])
        k = k + 1

If you wanted the default presets as well, you’d have to check with the Open Folder button in the palette presets menu and see if app.fs contains a path that will take you to the directory, or nearly there.

1 Like