Search code examples
colorsapplescriptadobe-indesign

Create Colour in InDesign CS5 with CMYK values from user input


I'm trying to create a script which, in the process of opening a template file, asks the user for a set of CMYK values.

The idea is to then either change the value of an existing colour (called "Primary Colour") therefore changing the colour of every item to which it is applied...or add this new colour and delete 'Primary Colour' replacing it with new colour.

The problem is I can't get past creating a new colour with user input values. I can create a new colour with;

 set New_Swatch to make color with properties {name:"New Primary Colour", model:process, color value:{82,72,49,46}}

however as soon as I try to replace the color value with a variable I get the error;

"Adobe InDesign CS5 got an error: Invalid parameter."

Here is a snippet of code in context;

set primaryColour to text returned of (display dialog "Enter CMYK calues of Primary Colour (separated by commas e.g. 0,0,0,0)" default answer "") as string

tell application "Adobe InDesign CS5"
 activate
 tell active document
    set New_Swatch to make color with properties {name:"new", model:process, color value:primaryColour}
  end tell
end tell

Any help gratefully received.


Solution

  • I currently use this:

    set primaryColor to text returned of (display dialog "Enter CMYK values of Primary Colour (separated by commas e.g. 0,0,0,0)" default answer "") as string
    set text item delimiters to ","
    set colorvalue to {}
    repeat with color from 1 to count of text items of primaryColor
       copy (text item colour of primaryColor as number) to end of colorvalue
    end repeat
      set colorname to "TEST"
    tell application "Adobe InDesign CS5"
       activate
       tell active document
        set newcolor to make color with properties {name:colorname, space:CMYK, model:process, color value:colorvalue}
       end tell
    end tell
    

    Why? Because it works. It is not pretty and it was not my first, or even 10th method to get the job done...Why this works? No idea...

    It just does. You would think that:

      set text item delimiters to ","
      set {C,M,Y,K} to text items of primaryColor
    

    ...

      set newcolor to make color with properties {name:colorname, space:CMYK, model:process, color value:{C,M,Y,K}}
    

    Would do the trick, but it doesn't... I'm sure your attempts so far have proven just how much of a pain this particular function is.