Posts in Category "Scripting"

Selection to PDF Script

Publishing consultant Martinho Da Gloria (creator of the wonderfully useful Layout Zone script add-on for InDesign) has made another free script available for InDesign users: SelectionToPDF. As the name would lead one to believe, the script enables you to select one or more object in InDesign, and export just that selection to a PDF file, not the whole page on which it lives. Cari Jansen has a good blog post on the script with step-by-step instructions and screen shots.

Layout Zones 1.0b14 Now Available

Martinho da Gloria of Automatication has updated the Layout Zones script to fix a font problem and a menu location issue on Windows. You an get the latest version at InDesign Secrets.

Layout Zones How-To

Installing the Layout Zone script:

  • Unzip the script and put the Layout Zones folder in the root level of InDesign’s Scripts folder.

Continue reading…

Cool (free!) Layout Zones Script

Today Martinho da Gloria of Automatication is releasing the first version of a script that enables a use to select InDesign page elements and convert them to a placed InDesign file automatically.

The script enables a workflow in which different InDesign users can work on different sections of the same page simultaneously.

In addition, the script also enables the user to convert the placed InDesign file back to native objects…in other words, it enables you to "round trip" the page elements into a placed InDesign file and back to native elements again.

Continue reading…

Ignore Textwrap Script

Dave Saunders was kind enough to write Russell Viers a script that toggles a text frame’s Ignore Text Wrap setting.

Copy and paste the javascript code into a text editor, save it with the name ToggleTextWrap.jsx, and drop it into your scripts folder. Because it’s a javascript it will run on both Mac and Windows platforms. Note: the script has not been written to deal with multiple selected frames.

//DESCRIPTION: Toggle text wrap of selected or active text frame
try {
app.selection[0].textFramePreferences.ignoreWrap =
} catch (e) {
try {
= !app.selection[0].parentTextFrames[0].textFramePreferences.ignoreWrap
} catch (e) {}

Once you’ve installed the script, you can use InDesign’s Keyboard Shortcut Editor to assign the shortcut of choice to the script. Just open the editor, pull down the Product Area menu and choose Scripts. Then, scroll down the list until you find your new script, select it and assign your shortcut. At that point you don’t even have to have the Scripts palette open. Hitting the shortcut executes the script.

Celebrity Keyboard Shortcuts: Dave Saunders

Dave Saunders is one of the planet’s most knowledgeable PageMaker and InDesign users. He’s a world class script writer for InDesign, and, along with his wife Pam, the owner and founder of PDS Associates. Check out their website for InDesign tips, scripts, and publishing services. Dave is also a frequent contributor to the InDesign Scripting Forum.

Dave shares the following favorite keyboard shortcut edits (Dave is a Mac user, so, once again, Windows users will need to adapt these shortcuts to the Windows environment. I clearly need to find more experts who do their shortcut edits on Windows). Many of Dave’s keyboard shortcuts trigger scripts that he’s written for InDesign:

  1. I swap cmd+ctrl+V and cmd+ctrl+Shift+V because I often want to paste in place and rarely paste inside. This also makes cmd+ctrl+V consistent with PageMaker.
  2. I assign cmd+Shift+W to fit page in Window. (A la FreeHand.)
  3. I assign ctrl+~ to a script that toggles the two characters on either side of the insertion point.
  4. I assign ctrl+A to a script that presents a list of that last 15 scripts I’ve run as well as all the scripts at the first level down in the Palette so I can easily repeat recent scripts and get at most palette scripts without having the palette consuming acres of screen space.
  5. I assign ctrl+opt+A to a script that runs any script anywhere in the file system by throwing up a dialog–it also adds that script to the recent list used by the previous script I mentioned. This means that if I’m working on a scripting project, I can keep the scripts with the client’s files where they’ll be backed up, and after calling them with this shortcut they’re available in the "last 15 list" for as long as I need them.
  6. I assign ctrl+W to a script called Reset Window Size that overrides the annoying default window sizes that InDesign tries to foist on me and instead uses a size that is kept in a default file (this allows me to run the same script on any machine or monitor because if the script fails to find a default file and there is an open window, it offers to make the current active window the default for that machine).
  7. I assign ctrl+1 to a similar script that makes the window half as wide as above (using another default text file in the same way). If a window is already occupying those coordinates, it puts the new window to the right of that other window, allowing me to easily have two windows side by side on my 20-inch monitor.
  8. I assign ctrl+opt+1 to a variation of this last script that always positions the front window at the designated coordinates. This allows me to see ESTK on the right and an InDesign window on the left.
  9. Nearly forgot: I assign ctrl+M to merge table cells.

I also hate the fact that cmd-H now hides InDesign. It is elevating my blood pressure each time InDesign disappears on me at least three or four times a day.

Export All Stories Script

I recently posted this useful script by Olav Kvern on another forum, but thought I’d post it here as well so that more users would be aware of it.

This script extracts all the separate stories in an InDesign document, concatenates and saves them into a single text file. When you do the export you have your choice of formats (.txt, .rtf, and tagged text), and whether or not you want separator lines inserted between the stories.

This script can be very useful when you want a quick and efficient way to re-purpose the text content of an InDesign document in another application.

To use the script, just copy and paste the javascript code below into a text editor and save it as a text only file with a .jsx extension. Then put it in your InDesign Scripts folder. This script was written for InDesign CS3, but runs on CS2 as well (on both Mac and Windows, because it’s a javascript).


//An InDesign CS3 JavaScript
//Exports all of the text in the active document as a single
//text file. To do this, the script will create a new document,
//combine the stories in the new document using export/import,
//and then export the text from the new document.
if(app.documents.length != 0){
if(app.documents.item(0).stories.length != 0){
function myGetFileName(myDocumentName){
var myFilePath = File.saveDialog("Save Exported File As:");
if(myFilePath != null){
myDisplayDialog(myDocumentName, myFilePath);
function myDisplayDialog(myDocumentName, myFilePath){
//Need to get export format, story separator.
var myExportFormats = ["Text Only", "Tagged Text", "RTF"];
var myDialog = app.dialogs.add({name:"ExportAllStories"});
var myExportFormatDropdown = dropdowns.add({stringList:myExportFormats, selectedIndex:0});
var myAddSeparatorCheckbox = checkboxControls.add({staticLabel:"Add separator line", checkedState:true});
var myResult =;
if(myResult == true){
var myExportFormat = myExportFormats[myExportFormatDropdown.selectedIndex];
var myAddSeparator = myAddSeparatorCheckbox.checkedState;
myExportAllText(myDocumentName, myFilePath, myExportFormat, myAddSeparator);
function myExportAllText(myDocumentName, myFilePath, myExportFormat, myAddSeparator){
var myStory;
var myTempFolder = Folder.temp;
var myTempFile = File(myTempFolder + "/tempTextFile.txt");
var myNewDocument = app.documents.add();
var myDocument = app.documents.item(myDocumentName);
var myTextFrame = myNewDocument.pages.item(0).textFrames.add({geometricBounds:myGetBounds(myNewDocument, myNewDocument.pages.item(0))});
var myNewStory = myTextFrame.parentStory;
for(myCounter = 0; myCounter < myDocument.stories.length; myCounter++){
myStory = myDocument.stories.item(myCounter);
//Export the story as tagged text.
myStory.exportFile(ExportFormat.taggedText, myTempFile);
//Import (place) the file at the end of the temporary story.
//If the imported text did not end with a return, enter a return
//to keep the stories from running together.
if(myCounter != myDocument.stories.length -1){
if(myNewStory.characters.item(-1).contents != "\r"){
myNewStory.insertionPoints.item(-1).contents = "\r";
if(myAddSeparator == true){
myNewStory.insertionPoints.item(-1).contents = "—————————————-\r";
case "Text Only":
myFormat = ExportFormat.textType;
myExtension = ".txt"
case "RTF":
myFormat = ExportFormat.RTF;
myExtension = ".rtf"
case "Tagged Text":
myFormat = ExportFormat.taggedText;
myExtension = ".txt"
myNewStory.exportFile(myFormat, File(myFilePath));
function myGetBounds(myDocument, myPage){
var myPageWidth = myDocument.documentPreferences.pageWidth;
var myPageHeight = myDocument.documentPreferences.pageHeight
if(myPage.side == PageSideOptions.leftHand){
var myX2 = myPage.marginPreferences.left;
var myX1 = myPage.marginPreferences.right;
var myX1 = myPage.marginPreferences.left;
var myX2 = myPage.marginPreferences.right;
var myY1 =;
var myX2 = myPageWidth – myX2;
var myY2 = myPageHeight – myPage.marginPreferences.bottom;
return [myY1, myX1, myY2, myX2];

When bad things happen to good script panels…

The other day most of my cool scripts for InDesign CS3 just suddenly quit working. Without any warning or explanation, they just stopped executing themselves, rendering my scripting palette an inviting but mostly inert list of good productivity intentions. This not the sort of behavior one expects or appreciates from one’s favorite application, and I have to say that I took it rather personally. Betrayal may be too strong a word, but if you’ve ever loved and lost your scripts, you know what I mean.

Fortunately, scripting deity Olav Kvern was in his office and was kind enough to diagnose my problem immediately. It seems that somehow InDesign’s scripting preferences had been altered without my knowledge…and that’s the way it will most likely happen to you as well.

InDesign’s scripting guides explain it in a bit more detail, but the short version is that you can tell InDesign (via a script, of course) whether or not to allow alerts and dialog boxes to be displayed when a script is executed. This can be a very useful thing to tweak when you’re running scripts that know exactly what they’re doing and can’t be bothered by unwanted alerts and other unnecessary interruptions by InDesign. On the other hand, turning off this setting can also block the execution of any script that wants to generate an alert or dialog box within InDesign. Dang.

It’s an important requirement of good scripting hygiene to restore alert and dialog generation if you’ve exercised the option of turning it off for the purposes of executing a script in the most efficient way. It’s analogous to turning off one of the breakers in your electrical panel in order to install a new light fixture or perform a repair —if you want lights to be able to come back on when you need them, you need to flip the breaker switch back to the ‘on’ position when you’re done with your repair.

What probably happened to me was that I ran a script that altered the userInteractionLevel property, but neglected to restore it to its original state as part of the completion of its mission. The fix is to run a script that restores that setting to its proper state.

Here’s the javascript you need should this ever happen to you:

app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;

Copy and paste this text into a text editor and save it into InDesign’s scripts folder with a name that describes what it does. Olav named mine RestoreUI.jsx. All it does is restore the user interaction script preference to its original, fully functional state.