Another Set of InDesign Scripts

I like posting about these every once in a while. It reminds me of some things I’ve worked on and ways I’ve made my work easier. If you haven’t seen them, my other posts on InDesign scripts are here and here.

Check Swatch Types

I work mostly in print, so I need my swatches to be CMYK. The files I get, however, may have been initially built by someone who isn’t aware of that. I wrote this function to check if there are any non-CMYK swatches in the document. It could easily be modified to return the name of the swatches.

function AreSwatchesCMYK(){
var s = myDoc.swatches;
var temp;
for(var i = 4; i < s.length; i++){
temp = s[i].space;
if(temp != 'CMYK'){
return false;
}
}
return true;
}

If you’re interested in finding other color types, just switch ‘CMYK’ to ‘RGB’ or ‘LAB’.

Set Ruler Units

The standard at my work is to use picas, but it’s much easier for most of the designers to work in inches or centimeters. Switching the units isn’t difficult to do manually, but I like placing this function in batch scripts or other validation type scripts so that I don’t have to do it manually.

function SetUnitsToPicas(){
myDoc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.PICAS;
myDoc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.PICAS;
}

If you don’t want picas, just change it to whatever unit you prefer.

Scrolling Alert

I can’t take credit for writing this one. I found it on Adobe’s scripting forum, here. You can look there if you want to see all the background. By default, InDesign alert boxes are static, so if there is a lot of text the alert box is either very large or it cuts off the excessive text. This function creates an alert with a scrollable text field. I’ve found it very useful in displaying warnings or errors where I need to give instruction.

function alert_scroll (title, input){
if (input instanceof Array)
input = input.join ("\r");
var w = new Window ("dialog", title);
var list = w.add ("edittext", undefined, input, {multiline: true, scrolling: true});
list.maximumSize.height = w.maximumSize.height-100;
list.minimumSize.width = 550;
w.add ("button", undefined, "Close", {name: "ok"});
w.show ();
}

Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s