Skip to main content
tobiask43046735
Inspiring
March 8, 2017
Answered

How to truly silently open a document?

  • March 8, 2017
  • 1 reply
  • 545 views

I'm using a script (see also related question) to export all documents of a book to IDML:

  1. var contents = app.activeBook.contents; 
  2. for(var i=0, content; i < contents.length; i++) { 
  3.     content = contents
  4.     var filename = content.fullName.fsName; 
  5.     var document = app.open(filename, showingWindow=false); 
  6.     var idmlname = filename.substr(0, filename.lastIndexOf(".")) + ".idml"
  7.     document.exportFile(format=ExportFormat.INDESIGN_MARKUP, to=File(idmlname)); 
  8.     document.close(saving=SaveOptions.NO); 

I'd like this process to be as unattended as possible, but unfortunately sometimes a cross-reference is outdated and I'm asked to update it there might also be other user-interaction interruptions I haven't yet encountered but would also like to cover).

Is there any way to open a document in a "yeah, just open it the way it is without asking the user"?

This topic has been closed for replies.
Correct answer TᴀW

But before you exit, make sure to set it back!

try{

     app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;

}

catch(_){}

finally{

     app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL);

}

Ariel

1 reply

tpk1982
Legend
March 8, 2017

use the below line in first of your code..

app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT; 
TᴀW
TᴀWCorrect answer
Legend
March 8, 2017

But before you exit, make sure to set it back!

try{

     app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;

}

catch(_){}

finally{

     app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL);

}

Ariel

id-extras.com | InDesign tools & scripts for typesetters, form designers, and translators