Home > InDesign Scripts > Document swatches selector

Document swatches selector

Like I said in previous post, ‘Find colored words‘, we will create swatches selector. This is not my script, and I will credit author on the end of this post. You can find this post on Adobe’s InDesign scripting forum. So let’s get started.

I hope that you are familiar with dialogs in InDesign. If you’re not, you have finished script here so you can just copy/paste it in your script.

Let’s just run through script. First we call swatchSelect, and window is created. We fill mySwatches with document swatches and parse every item name to dropdown box. If you click ok, myReturn will be true, and mySwatchesResult returns swatch numeric index. So swatchSelect is now complete, and we go to displaying result. As almost everything in InDesign, swatches are in Array too, so it’s really easy to get selected swatch name like you can see in line 4.

If you are familiar with dialogs, you can modify it to your needs.


if (myReturn) {
     alert("You selected " + app.activeDocument.swatches[mySwatchesResult].name);
}else {
     alert("You canceled dialog.");

function swatchSelect(){
   with(myDialog = app.dialogs.add({name:"Swatches in the active document"})){
      myDialogColumn = dialogColumns.add();
         staticTexts.add({staticLabel:"Swatches "});
         mySwatches = app.activeDocument.swatches;
            myDropdown = dropdowns.add();
            myDropdown.stringList = mySwatches.everyItem().name;
            myDropdown.selectedIndex = 0;
      myReturn = myDialog.show();
      if (myReturn == true){
         mySwatchesResult = myDropdown.selectedIndex;
         return mySwatchesResult;
      } else {

If you want to combine this with Find colored words, for start try to change line 4 with this:

app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;

app.findGrepPreferences.findWhat = "\\w{2,}";
app.findGrepPreferences.fillColor = app.activeDocument.swatches[mySwatchesResult];

var result = Number(app.activeDocument.findGrep().length);


So we passed mySwatchesResult (number) to fillColor preference of GREP find, but we need to pass a swatch, not just number, so we select swatch like this:


Well, that’s it. You can maybe built this in some bigger dialog, or on different way. Don’t forget to check Find colored words for other search options.

I want to credit Kasyan Servetsky as author of this short snippet.

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: