I've been picking away at this script, the idea is to have a dialog that steps through the layers in the document and has the user pick from a dropdown to set a text box on the slug. The issue I'm having is the call to add the text box seems to be dying silently with no error message. I'm sure there's something obvious I'm missing. Hoping that someone can help me spot the issue.

The current code for the text box is placeholder, I tore out the function I was using and just put in the most basic version to see if I could isolate the error. There are also some alerts placed so I could see how far the script was getting before it died.

//get document assigned to var
var doc = app.activeDocument;

//get # of layers
layerNum = doc.layers.length;

//get # of pages
pageNum = doc.pages.length;

//layer blacklist
//used to turn layers on and off
var layerBlacklistVisibility = ["Crop Cubed"];
var layerBlacklistLock = ["Crop Cubed","Slug Cubed","Tap Test","Color Spec Cubed","CONTENT GRAPHICS","CONTENT FORMATTING","SYSTEM"];

var closeState = false;

var layerIncrement = 0;

var dialog = new Window("dialog", "LOB Labeler");

var group1 = dialog.add("group", undefined, {name: "group1"}); 
group1.orientation = "column"; 
group1.alignChildren = ["center","center"]; 
group1.spacing = 0; 
group1.margins = 0; 

var statictext1 = group1.add("statictext", undefined, undefined, {name: "statictext1"}); 
statictext1.text = "Layer Name:"; 

var statictext2 = group1.add("statictext", undefined, undefined, {name: "statictext2"}); 
statictext2.text = ""; //this will be updated dynamically

var panel = dialog.add("panel", undefined, "Select a LOB:");
var dropdown_array = ["Select","ACQ","XS","AiA","NewBuild","Fiber","Wireless"]; 
var dropdown = panel.add("dropdownlist", undefined, dropdown_array);
dropdown.selection = 0;

var buttonGroup = dialog.add("group");
var cancelButton = buttonGroup.add("button", undefined, "Cancel");
var okButton = buttonGroup.add("button", undefined, "Next");


Array.prototype.indexOf = function ( item ) {

  var index = 0, length = this.length;

  for ( ; index < length; index++ ) {

    if ( this[index] === item )

      return index;


  return -1;



//this handles the OK button
okButton.onClick = function() {

    alert("3 here!");

    //when the user clicks OK fire this

    //if close is true
    //if (closeState = true) {


//this handles the cancel button, no need to change here
cancelButton.onClick = function() {




// Call the function to handle the initial layer

//call dialog


function handleLayer() {

  if (layerIncrement >= layerNum) {
    // No more layers to process


  var currentLayer = doc.layers[layerIncrement];
  var layerName = currentLayer.name;

  if (layerBlacklistVisibility.indexOf(layerName) !== -1 || layerBlacklistLock.indexOf(layerName) !== -1) {

    // Increment and get next layer name


alert("1 here!"); //flag so I can track where the script is dying

  } else {

    // Set layer to unlocked
    currentLayer.locked = false;

    // Set layer to visible
    currentLayer.visible = true;

    statictext2.text = layerName; // Update layer name in the dialog

alert("2 here!"); //flag so I can track where the script is dying



function dropdownCallback() {

    //this sets the dropdown selection to a variable
    var selectedLOB = dropdown.selection.text;

    alert("4 here!"); //flag so I can track where the script is dying

    //this makes a text box from the dropdown info
    //this is a placeholder, was seeing if the simplist version would work
    var textFrame = app.documents.add().textFrames.add();
    textFrame.properties = {

        geometricBounds : [ 0,0,100,100 ],
        strokeWidth : 0,
        fillColor : "None",
        contents : "Hello World!"


  if (layerIncrement === layerNum - 2) {
    okButton.text = "Finish";
    closeState = true;



  • As a guess. A dialog window (unlike a palette window) can't change a document untill the window is closed. To change the document you have to close the windows first and then make the changes in the document according gathered from the windows data. It should be done step by step: 1-show the window, 2-gather the data via the window's interface, 2-close the window, 4-change the document. Jul 3, 2023 at 18:09

1 Answer 1


Not sure what exactly the script is supposed to do. As a possible quick fix you can try to change a type of window from dialog to palette. A palette has access to a document any time. A dialog can't change a document until the dialog window is open.

To make a palette add these two lines at the start of the script:

#target "InDesign"
#targetengine "session"

And change the line:

var dialog = new Window("dialog", "LOB Labeler");

with this:

var dialog = new Window("palette", "LOB Labeler");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.