Skip to main content
Participant
March 5, 2016
Question

How do I get a reference to the current swatches?

  • March 5, 2016
  • 1 reply
  • 949 views

I'm a digital painter and comic book colorist, and I'm always on the lookout for ways to speed up my palette creation process. I already have a script that samples all the unique colors of a document and saves them to the swatches panel. What I want now is a way to sort the current swatches by either their H, S, or B values. Does anyone know how I could get an object reference to the current swatches?

To be clear, I know how I could sort an array of colors BEFORE saving them to the swatches panel. I'm looking for a way to take whatever is already in the swatches panel, and sort by hue, saturation, or brightness on the fly without having to save, parse, and reorder an ACO file or something.

This topic has been closed for replies.

1 reply

Inspiring
March 5, 2016

AFAIK, you can't sort the swatch palette in place. You need to go the ACO route.

Here's some code that might help if you don't already have it:

http://ps-scripts.cvs.sourceforge.net/viewvc/ps-scripts/xtools/xlib/ColorSwatches.jsx

Participant
March 6, 2016

As much as I don't want you to be right, I've hit a wall trying to get anything more than grabbing a list of strings for each swatch's name by cycling through the Preset Manager. It's baffling that there's no way to get at this through the object model, honestly.

I've managed to add the sorting behavior I was after to my existing color-sampling script, and I'm going to use the code from the file you linked to to output a sorted ACO from whatever colors may be in the swatches panel at a given time. Close enough, I guess.

Thanks!

oliverIntergrafika
Inspiring
March 6, 2016

PS is a half legged giant from the scripting perspective. It's JS DOM seems abadomned since years and the low level scripting "interface" can't be handled by a mortal being. The Script listener plugin don't log the interresting part. BUT it logs the tremendously useful Visual Basic and Applescript instead!