# Change the palette of several sprites

**URL:** https://community.aseprite.org/t/change-the-palette-of-several-sprites/4299
**Category:** Scripts & Extensions
**Created:** [November 27, 2019, 1:24pm UTC](https://community.aseprite.org/t/change-the-palette-of-several-sprites/4299 "2019-11-27T13:24:33Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![dacap](https://community.aseprite.org/user_avatar/community.aseprite.org/dacap/32/10_2.png) [@dacap](https://community.aseprite.org/u/dacap)
#### Post date: [November 27, 2019, 1:24pm UTC](https://community.aseprite.org/t/change-the-palette-of-several-sprites/4299/1 "2019-11-27T13:24:33Z")

</div>

_(Before using these scripts create a backup of your sprites)_

A possible way to update the palette of several sprites automatically would be to [create a Bash](https://community.aseprite.org/t/command-batch-save-files-contained-in-a-folder/2092/2) script that for each file uses a Lua script that converts the palette in the sprites.

Imagine that we have a set of sprites called `player.aseprite`, `enemy.aseprite`, etc. And a palette in `global_palette.aseprite`. We could create the following Bash script that for each `.aseprite` file calls a `fix_palette.lua` script:

```bash
# Adjust the $aseprite variable to the specific path of your platform
aseprite=“C:/Program Files (x86)/Steam/steamapps/common/Aseprite/aseprite.exe”
for file in *.aseprite ; do
  $aseprite -b -script-param file=$file -script fix_palette.lua
done

```

Then in the `fix_palette.lua` file:

```lua
-- Load the global palette
local palette = Palette{ fromFile='global_palette.aseprite' }
if not palette then
  print('there is no global_palette.aseprite')
  return 1
end

local sprite = app.open(app.params['file'])
if sprite then
  sprite:setPalette(palette)
  -- Or do other modifications in sprite.palettes[1]...

  -- Warning: we are overwriting the original file
  sprite:saveAs(sprite.filename)
end

```

More info about [sprite.palettes](https://github.com/aseprite/api/blob/master/api/sprite.md#spritepalettes), [sprite:setPalette()](https://github.com/aseprite/api/blob/master/api/sprite.md#spritesetpalette), or [Palette{}](https://github.com/aseprite/api/blob/master/api/palette.md#palette-1).
