In May 2010 Marc Autret posted this interesting blog: Show Local Formatting in InDesign CS4/CS5, where he shows how an undocumented feature of InDesign can be put to good use. If you set TextPreference.enableStylePreviewMode to true, ID suddenly shows red lines marking local character and paragraph style overrides. A very neat find, one that I use all the time to check my documents for (uh) "neatness".
I just ran across this obscure scripting preference whilst looking for something entirely unrelated -- but something in the description caught my eye.
| enableStylePreviewMode | bool | r/w | If true, highlights character and paragraph styles with colored backgrounds. |
Regular lurkers might remember the puzzling "previewColor" properties in Paragraph and Character Style. Now that's what this is for!
This script will add background colors to a paragraph style and a character style, and then show them in your document. No need to worry about your document, despite the name they only appear in Normal view. In Preview mode they disappear, and they will not print or export to PDF.
app.activeDocument.textPreferences.enableStylePreviewMode = true;
app.activeDocument.paragraphStyles.item("Body Text").previewColor = UIColors.YELLOW;
app.activeDocument.characterStyles.item("Italics").previewColor = UIColors.CYAN;
Upside or downside is this comes with those override red line markings for free. Oh well. Perhaps it's a preference in CS6 -- and I wouldn't mind if the preview color could be set in the style options either, for now it needs a script.
I'm definitely seeing some weirdness, though (in CS5 7.0.4 on Mac 10.6.8). If I do this:
app.selection[0].appliedParagraphStyle.previewColor = UIColors.YELLOW
I see this:
Not yellow. If I assign an RGB value, like [255, 0, 0], it takes, but doesn't display any highlight color. I checked how other things, like xmlTags, that use the UIColors, look, and the colors do display properly there.
Does anyone else see this?
@Jongware – Cool. Thanks for sharing.
Same observation, though different color: an asigned RGB value like [255,255,0] (=bright yellow) turns to nothing, UIColors like YELLOW or CYAN turn into different colors:
var _d = app.activeDocument;
var _allParaStyles = _d.allParagraphStyles;
var _UIColor = UIColors.YELLOW;
_d.guidePreferences.rulerGuidesColor = _UIColor;
_d.textPreferences.enableStylePreviewMode = true;
_allParaStyles[1].previewColor = _UIColor;
app.selection[0].contents = "UIColors."+_UIColor.toString();
Look at the vertical guide. Its color is "UIColors.YELLOW":
Here a version with "UIColors.CYAN":
(InDesign CS5.5 v7.5.2 German with OSX 10.6.8)
Uwe
Nice find!
I'm also seeing color offset, also, colors from GRID_BLUE and beyond, doesn't work.
var
mD = app.activeDocument,
pS = mD.paragraphStyles, pSn,
tB = mD.textFrames.add ( { geometricBounds: [0, 0, "200mm", "200mm"] } );
mD.textPreferences.enableStylePreviewMode = true;
for each ( color in UIColors ) {
try { pSn = pS.add ( { name: color.toString () } ); } catch ( _ ) { pSn = pS.itemByName ( color.toString () ) };
pSn.previewColor = color ;
tB.insertionPoints [-1].contents = "Test " + color.toString () + "\r";
tB.paragraphs [-1].appliedParagraphStyle = pS.itemByName ( color.toString () );
}
--
Marijan (tomaxxi)
@Jongware – applying a custom color is crashing InDesign CS4 in the moment you switch from "Preview" (w) to "Layout" view; or immediately, if you are already in "Layout" view. That is not new to me. Applying a custom color to a page in the pages panel would crash (BEGIN EDIT) InDesign CS5 and CS5.5 (END EDIT) as well, if the palette is visible in the UI.
(BEGIN EDIT:
Example for CS5 and CS5.5:
app.documents[0].pages[0].pageColor = [255,255,0];
will crash InDesign in the moment the pages panel is visible. If it is hidden behind other UI elements or not visible at all, InDesign will not crash.
(END EDIT)
In CS5 or CS5.5 applying a custom color to a paragraph style with previewColor results in nothing.
Uwe
Message was edited by: Laubender
There is an order to how the UIColors are off, though—they're all off by two. This works (although LIGHT_BLUE and RED are gone); I ran it on a document with an empty text frame.
function main() {
var doc = app.activeDocument,
colors = [],
map = {},
story = doc.stories[0],
i, style;
for (i in UIColors) {
colors[colors.length] = UIColors[i];
}
for (i = 2; i < colors.length; i++) {
map[colors[i].toString()] = colors[i - 2];
}
for (i in map) {
style = doc.paragraphStyles.add({name: i});
style.previewColor = map[i];
story.insertionPoints[-1].contents = "UIColors." + i + "\r";
story.paragraphs[-1].appliedParagraphStyle = style;
}
doc.textPreferences.enableStylePreviewMode = true;
}
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Show Preview Colors");
Then I guess the person who isn't me who is making the dialog to manage this could at least use e.g. UIColors.GREEN for CS4 and map.GREEN for CS5.
@Jongware – and the following script will crash InDesign CS4 (not CS5 and CS5.5) if in "Layout" view, but not in "Preview" (text frame selected):
//CAUSION: Will crash InDesign CS4 immediately if in "layout" view.
//Will crash InDesign CS4 after applying previewColor if changing from "preview" view to "layout" view!
var d = app.documents[0];
var sel = app.selection[0]; //TextFrame
d.textPreferences.enableStylePreviewMode = true;
var RGBcolor = [255,255,0]; //Bright yellow color
sel.insertionPoints[0].contents = "RGBcolor "+"["+RGBcolor.toString()+"]";
sel.insertionPoints[0].appliedParagraphStyle = d.allParagraphStyles[1];
d.allParagraphStyles[1].previewColor = RGBcolor;
Uwe
Hi Jongware,
Shame on me! I just discovered this thread today (June 4!) thanks to a link found at http://indesignsecrets.com/style-highlighting.php
It follows that when I posted in May the very first version of StyLighter — http://www.indiscripts.com/post/2012/05/the-hidden-way-to-highlight-st yles — I had not the slightest knowledge of everything that was discussed here!
So I really want to apologize for having covered up (although unintentionally) your own discovery.
@+
Marc
Apologies not necessary. That previewColor property has been a mystery for quite some time, and when I finally found out what it is supposed to do, it seemed to be so bug-ridden that I quickly steered away from it and I gave up attempting to make any sense of it. But your script just avoids those bugs popping up!
As I said in the IDS post: it's rather sad the Adobe team gave up on further developing this great hidden feature into a full one; and it's downright worrying that they left that legacy code in CS5 and later, so it could get infested with all those nasty little bugs. It leads me to think: how many more 'dead' code is there, in CS5, 5.5 and now in CS6? Could that be the reason later versions are so much slower and more buggy than my trusty CS4?
(Point in fact.
In CS4 and earlier on the Mac, all plugin resources are gathered into neat, small packages inside a single large indexed file. That makes sense, because every single plugin resource is just a couple of bytes long -- say, a single icon, or a single string "Menu Item Name". With CS5, the programmers suddenly took a Lazy Turn and wrote out every single resource as a single small file. That means that
1. (Annoying!) Since hard disk space is allocated by the kilobyte (typically 4Kb chunks), 10 tiny resources totalling 1 Kb now will suddenly occupy 40 Kb of disk space. Sure, hard disk space is cheap. Apparently, it's even cheaper than doing some programming -- or even just using the load code from the last version!
2. (Frustrating!) Locating, opening, loading, and then closing a single file takes time and resources, but after a file got loaded into memory, you can do with it whatever you want. Locating, opening, loading and then closing each of the dozens of small files per plugin takes lots of time. Is that the reason CS5.5 starts up so incredibly slow? Jongware sez: yeah for sure it won't help.
/Point in fact).
Jongware,
the conversion to those files was probably undertaken to get away from OSX Carbon resource manager which is not thread safe and not available as 64bit version. Why Adobe did not implement anything less wasteful is beyond me, but they are again in good company with Apple, who uses packages / folder hierarchies galore where frugal old school developers stuffed everything into a single resource fork.
On the other hand CS5.5 takes about two seconds to launch on my current Mac (with SSD) while CS4 took about 30 seconds on an old disk based machine.
North America
Europe, Middle East and Africa
Asia Pacific