Colors 使用用户输入的CMYK值在InDesign CS5中创建颜色

Colors 使用用户输入的CMYK值在InDesign CS5中创建颜色,colors,applescript,adobe-indesign,Colors,Applescript,Adobe Indesign,我正在尝试创建一个脚本,在打开模板文件的过程中,该脚本要求用户提供一组CMYK值 这样做的目的是改变现有颜色(称为“原色”)的值,从而改变应用该颜色的每个项目的颜色……或者添加该新颜色并删除“原色”,用新颜色替换 问题是我无法通过用户输入值创建新颜色。我可以创造一个新的颜色 set New_Swatch to make color with properties {name:"New Primary Colour", model:process, color value:{82,72,49,4

我正在尝试创建一个脚本,在打开模板文件的过程中,该脚本要求用户提供一组CMYK值

这样做的目的是改变现有颜色(称为“原色”)的值,从而改变应用该颜色的每个项目的颜色……或者添加该新颜色并删除“原色”,用新颜色替换

问题是我无法通过用户输入值创建新颜色。我可以创造一个新的颜色

 set New_Swatch to make color with properties {name:"New Primary Colour", model:process, color value:{82,72,49,46}}
然而,当我尝试用一个变量替换颜色值时,我得到了错误

“Adobe InDesign CS5出现错误:参数无效。”

下面是上下文中的一段代码

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
感谢您提供的任何帮助。

我目前使用的是:

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
为什么??因为它有效。这并不漂亮,也不是我完成工作的第一个,甚至第十个方法……为什么这样做有效?不知道

确实如此。你会认为:

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


这会起作用,但不会。。。我相信你到目前为止的尝试已经证明了这个特殊功能有多痛苦

您可能还希望使用AppleScript“choose color”命令,该命令显示一个颜色选择器,而不是向用户显示一个对话框,用户必须在其中输入数字颜色值

本例将RGB颜色作为文本插入BBEdit窗口,但您可以使用相同的原理将CMYK颜色作为文本插入InDesign

tell application "BBEdit"
    activate
    set theColorValues to choose color
    set theR to round (the first item of theColorValues) / 257
    set theG to round (the second item of theColorValues) / 257
    set theB to round (the third item of theColorValues) / 257
    set theRGBColor to "rgb(" & theR & ", " & theG & ", " & theB & ")"
    set selection to theRGBColor
end tell

将primaryColor设置为返回的文本(显示对话框“输入原色的CMYK值(用逗号分隔,例如0,0,0,0)”默认答案“”作为字符串

将文本项分隔符设置为“,”

将colorvalue设置为{}

使用颜色从1到primaryColor的文本项计数重复此操作 将(primaryColor的文本项颜色作为数字)复制到colorvalue的末尾

结束重复

将colorname设置为primaryColor

告诉应用程序“Adobe InDesign CC 2017”

激活

告诉活动文档

将newcolor设置为使用属性{name:colorname,space:CMYK,model:process,color value:colorvalue}生成颜色

结束语


end tell

Simon使用颜色选择器的方法将获取CMYK值,将其转换为RGB,然后最终生成CMYK。用户输入的值与最终结果不匹配。非常感谢你Lithodora…这真的让我头痛不已!我有一种感觉,我最初错误的原因是因为返回的值没有封装在{curly方括号}中,所以将colorvalue设置为{}我怀疑我会想到什么。我也注意到你对@Simon White…的评论。谢谢你的帮助Simon。我有一种感觉,这将成为有用的东西,我已经排队!
tell application "BBEdit"
    activate
    set theColorValues to choose color
    set theR to round (the first item of theColorValues) / 257
    set theG to round (the second item of theColorValues) / 257
    set theB to round (the third item of theColorValues) / 257
    set theRGBColor to "rgb(" & theR & ", " & theG & ", " & theB & ")"
    set selection to theRGBColor
end tell