Dispersion Design

< Back

Scripting InDesign Story Editor Preferences

2012-06-04

Introduction

If you are a heavy user of Adobe® InDesign®, you will probably be familiar with the Story Editor, a tool for viewing your document’s text on its own, separate from the layout and graphics, plain and without any special formatting. Text is displayed in the Story Editor similar to how you would see it in a plain text editing program such as Notepad (Windows), or TextEdit (Mac). This allows you to focus on the content without being distracted by the formatting.

The display settings for the Story Editor can be set in the InDesign preferences, allowing you to customize the color, font, size and various other settings. Since InDesign is highly scriptable, you can also write a script to set the Story Editor display preferences. This article will demonstrate how to use JavaScript to write a script to change the display settings of the InDesign Story Editor.

Story Editor Preferences = Galley Preferences

Poking around the InDesign scripting documentation, you might be surprised to find that the Story Editor preferences are actually located under ‘galleyPreferences’. It would appear that InCopy, another related Adobe product, has a Story Editor and a Galley Editor, and the settings for both these tools are stored together. We access the Story Editor preferences using JavaScript in the following way:

var editorPrefs = app.galleyPreferences;

Changing Individual Preferences

Individual settings can now be changed. For example, we can change the Story Editor font, font colour and background colour:

editorPrefs.displayFont = 'Arial';
editorPrefs.textColor = [0.5, 0, 0];		// Dark Red
editorPrefs.backgroundColor = [1, 1, 1];	// White

The InDesign API documentation lists all the settings that can be changed. Here are a few useful settings:

JavaScript nameExample
backgroundColoreditorPrefs.backgroundColor = [0.2, 0.9, 1.0];
displayFonteditorPrefs.displayFont = 'Arial';
displayFontSizeeditorPrefs.displayFontSize = '12 pt';
textColoreditorPrefs.textColor = [0, 0, 0];
showInfoColumneditorPrefs.showInfoColumn = true;
showParagraphBreakMarkseditorPrefs.showParagraphBreakMarks = false;

Interestingly, the InDesign API documentation states that the textColor and backgroundColor properties expect Red/Green/Blue (RGB) values between 0 and 255, but my version of InDesign appears to require values between 0 and 1.0.

Changing Multiple Preferences

Multiple preferences can also be set at the same time using the properties property:

editorPrefs.properties = {
	'displayFont': 'Arial',
	'backgroundColor': [0.95, 0.95, 1.0],
	'textColor': [0.5, 0, 0]
};

Show Hidden Characters

One option that is often used in the Story Editor is 'Show Hidden Characters'. This option is not set using the galleyPreferences. Instead, it is set using textPreferences. To show hidden characters, you would use:

app.textPreferences.showInvisibles = true;

And turning off hidden characters:

app.textPreferences.showInvisibles = false;

Script To Toggle Display Settings

We can now write a script that toggles between two different sets of Story Editor display settings each time the script is run.

var editorPrefs = app.galleyPreferences;

if (editorPrefs.showInfoColumn) {
	editorPrefs.properties = {
		'displayFont': 'Arial',
		'displayFontSize': '12 pt',
		'showInfoColumn': false,
		'showParagraphBreakMarks': false
	};
	app.textPreferences.showInvisibles = false;
} else {
	editorPrefs.properties = {
		'displayFont': 'Courier',
		'displayFontSize': '14 pt',
		'showInfoColumn': true,
		'showParagraphBreakMarks': true
	};
	app.textPreferences.showInvisibles = true;
}

Please feel free to download the completed StoryEditorToggleFormat script and try it for yourself.