0

I use a script which opens the story editor like this:

app.menuActions.itemByID(119793).invoke();

How can I close it programmatically? How can I detect whether it's opened or closed?

Shawn
  • 10,931
  • 18
  • 81
  • 126

2 Answers2

1

A story editor window may be closed with its close method.

Here is a function which closes the story editor window if it's open. It tests for the presence of a zoom property on the window to determine whether the window is a story editor or not (Thanks Loic Aigon for this idea)... There must be a better way of doing this but I haven't found it.

function closeStoryEditor() {
  var windows = app.activeDocument.windows,
    nbWindows = windows.length,
    i,
    closedWindow = false;
  for (i = 0; !closedWindow && i < nbWindows; i += 1) {
    if (!windows[i].hasOwnProperty("zoom")) {
      // Let us presume that a window without a zoom method is a story editor window...
      windows[i].close();
      closedWindow = true;
    }
  }
}
Tobias Kienzler
  • 25,759
  • 22
  • 127
  • 221
Shawn
  • 10,931
  • 18
  • 81
  • 126
0

To close it, it's…the same call ! if you want to check if the editor is already opened, you can loop through all open windows like this : app.activeDocument.windows.everyItem().name; and see for matches.

Loic http://www.loicaigon.com

Loic Aigon
  • 506
  • 3
  • 1
  • What test should I perform to determine whether the current window is the story editor window? – Shawn Jun 18 '12 at 21:19
  • 1
    the story editor seems to have no zoom info while the main window has. I never used this stuff so I can't warranty it's safe but it's the only clue I can think of right now. – Loic Aigon Jun 19 '12 at 16:52
  • Hmm, it seems that calling `app.menuActions.itemByID(119793).invoke();` a second time does not close the story editor window after all.. – Shawn Jun 19 '12 at 21:33
  • I can, however, test if a story editor window is opened using the absence of a zoom property on that window. Here is the code: http://pastebin.com/kLbDU7pC – Shawn Jun 19 '12 at 21:35
  • Nice one for the zoom property. For the menu invokation, it's weird. It worked here. What version do you use ? – Loic Aigon Jun 19 '12 at 23:14
  • Adobe InDesign CS6 (version 8.0) with ExtendScript Toolkit CS5 (3.5.0.52 ExtendScript 4.1.23 ScriptUI 5.1.37) – Shawn Jun 20 '12 at 13:04