-
Notifications
You must be signed in to change notification settings - Fork 33
/
ForegroundColour 2 InDesignSwatch.jsx
58 lines (44 loc) · 1.53 KB
/
ForegroundColour 2 InDesignSwatch.jsx
1
// This script will create a CMYK swatch in InDesign based on the foreground colour in Photoshop// Bruno Herfst 2014// Version 1.0/*<javascriptresource> <name>Foreground color to InDesign swatch</name> <category>CoverBuilder Extra</category></javascriptresource> */// Get the CMYK values from PSvar fc = app.foregroundColor;var foreGroundCMYK = [fc.cmyk.cyan,fc.cmyk.magenta,fc.cmyk.yellow,fc.cmyk.black];// The script to create a swatch in InDesignfunction addCMYKtoSwatch(c,m,y,k) { var myColorName = "C=" + parseInt(c) + " M=" + parseInt(m) + " Y=" + parseInt(y) + " K=" + parseInt(k); if (app.documents.length <= 0) { alert("Open a cover before sending colours."); exit(); } function doRound(num, roundDec) { var roundMulit = Math.pow(10,roundDec); return Math.round(num*roundMulit)/roundMulit; } var myDocument = app.activeDocument; var myColor = myDocument.colors.add(); myColor.properties = { name: myColorName, model: ColorModel.PROCESS, space: ColorSpace.CMYK, colorValue: [doRound(c,2),doRound(m,2),doRound(y,2),doRound(k,2)] }; alert("Added " + myColor.properties.name + " to swatches");}// the BridgeTalk Objectvar bt = new BridgeTalk();// the communication targetbt.target = "indesign";// The script to be executed as a Stringvar message = addCMYKtoSwatch.toString(); message += "\n addCMYKtoSwatch(" + foreGroundCMYK.toString() + ");";// assign to the object's body the messagebt.body = message; // send the message to the target appbt.send();