When considering the scripting language you want to use to automate Adobe InDesign, remember that it does not need to be an either/or situation. Once you learn one language, another is really not that hard. And, with do script you have the ability to take advantage of the strengths of any of the supported languages no matter which one you are working in.

Cross-language capability is just one of the reasons for getting familiar with do script. For instance, being able to store a script inside of an object opens the door to a wealth of automation possibilities.

One of the most used practical applications of do script is for creating a non-modal window. Modal windows, you will recall, must be closed before a script can continue its execution. Should you wish to have a window stay open while the script continues to run in the background requires a non-modal window.

As an example, suppose you have a script that will take a few seconds to run before anything appears on the screen. To keep the user from thinking that nothing is happening, you might want to display a message that the script is running.

For this you will want two sub-routines:

  1. One to display the window while the script continues to run in the background.
  2. The second one to close the window when the background processing has completed.

ExtendScript

Interestingly, javascript is used for the do script language to perform this function in ExtendScript. Here are the sub-routines (functions) written for ExtendScript:

//returns script to display a floating window 
function getStartScript(){
	var js = "#targetengine \"session\"" + "\n";
	js += "w = new Window ('palette', ' ');" + "\n";
	js += "var myText = w.add('statictext', undefined, 'WORKING...Please be patient');" + "\n";
	js += "w.show();"
	return js;
}
//returns script to close the floating window
function getEndScript(){
	var es =  "#targetengine \"session\"" + "\n";
	es += "w.hide();"+ "\n";
	return es;
}

At the point in your script when you want to display the window, you call the first routine (getStartScript):

var startScript = getStartScript();
app.doScript(startScript);

Follow this with a call to the background routine. When the background routine completes, call the routine to dismiss the window:

var endScript = getEndScript();
app.doScript(endScript); 

AppleScript

For AppleScript, the process is similar:

(*handler returns script to display floating window*)
on getStartSript()
   set js to "#targetengine \"session\"" & return
   set js to js & "w = new Window ('palette', ' ');" & return
   set js to js & "var myText = w.add('statictext', undefined, 'WORKING…Please be patient");" & return
   set js to js & "w.show();"
   return js
end getStartScript
(*handler returns script to close floating window*)
on getEndScript()
   set es to "#targetengine \"session\"" & return
   set es to es & "w.hide();" & return
   return es
end getEndScript

The script then calls the handlers from within a tell statement to the application:

tell application "Adobe InDesign CS5.5"
   activate
   set startScript to my getStartScript()
   do script startScript language javascript
   (*perform background processes, then use do script to close the window*)
   set endScript to my getEndScript()
   do script endScript language javascript
end tell

I constantly get reminded of how valuable do script can be, perhaps you will discover other applications as you work with your favorite scripting language.