Skip to main content
bluebeezle
Inspiring
June 6, 2016
Answered

Find and Replace Color

  • June 6, 2016
  • 1 reply
  • 2713 views

Hi guys,

I'm brand new to scripting for Photoshop, but I've used Extendscript for After Effects and JSFL for Flash/Animate.

I'm trying to make a script that will find every pixel of a specific color (meaning on every layer, as well) on an animated timeline (the animated timeline part would be nice, but is not mandatory) and change it to another, based on hex values, while leaving the alpha intact, and with no selection feathering. Whether this means creating a GUI with two color pickers, or just using the foreground and background colors in the toolbar, either works for me.

Unfortunately, the Image>Adjustments>Replace Color feature only works on one layer at a time.

Please let me know if this makes sense, and if you can help. Thanks!

This topic has been closed for replies.
Correct answer c.pfaffenbichler

AM stands for Action Manager.

That’s the kind of Photoshop JavaScript code one can record with ScriptingListener.plugin, check it out for recording Replace Color:

Adobe Photoshop Scripting | Adobe Developer Connection 

1 reply

c.pfaffenbichler
Community Expert
Community Expert
June 7, 2016

Generally I consider Replace Color useless for serious work.

But if it meets your needs and the problem is only applying it to multiple Layers then use a for-clause to iterate through the Layers and apply it to each one in turn.

AM code is usually faster but DOM code would also work; you need to consider, though, that Layers in Groups and filial to the Groups, not the Document, so activeDocument.layers.length would not take Layers in Groups into account.

bluebeezle
Inspiring
June 7, 2016

basically I'm doing pixel art, and some of the sprites will need alternate versions (palette swaps). I need an easy way to swap specific colors throughout all the grouped layers of a document to other specific colors. I'll be working in Javascript, but I can't seem to find a way to access the Replace Colors function, so that I can run it on every layer. I'll try to find another way to iterate through groups, as well.

Also, I'm brand new to this, and while I've recently become aware of DOM, I don't know what AM is.

c.pfaffenbichler
Community Expert
c.pfaffenbichlerCommunity ExpertCorrect answer
Community Expert
June 7, 2016

AM stands for Action Manager.

That’s the kind of Photoshop JavaScript code one can record with ScriptingListener.plugin, check it out for recording Replace Color:

Adobe Photoshop Scripting | Adobe Developer Connection