Search code examples
javascriptadobe-indesignextendscript

Changing an Indesign Swatch incrementally with Extendscript (JavaScript)


I have an InDesign doc with the swatch named "mySwatch" which is C10 M20 Y30 K40. I have written the line:

app.activeDocument.colors.item("mySwatch").colorValue = [9,19,30,41];

to change it to a specific set of values (9,19,30,41), but I would like to instead add or subtract from the existing values, let's say [-1, -1, unchanged, +1].

Is this possible?


Solution

  • You will have to get the values out by assigning them to a new variable.

    var myvalues = app.activeDocument.colors.item("mySwatch").colorValue
    

    Do your operations on them.

    myvalues[0] = myvalues[0] - 1
    

    Reassign them to your swatch.

    app.activeDocument.colors.item("mySwatch").colorValue = myvalues 
    

    (Not tested)