• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

Within book file (.indb), open SELECTED documents only?

Contributor ,
Jun 12, 2019 Jun 12, 2019

Copy link to clipboard

Copied

I have the below script which works in opening documents from InDesign Book files.

The problem is it opens ALL the documents, when I would like to get it to open only the selected documents.

Rummaged all through the Extend Script DOM, eventually landing on BookContent, but couldn’t figure out how to get the script to only open the selected docs contained in the book panel.

I’m guessing since there’s no OPEN menu item within the book panel’s fly-out menu, that maybe an Even Listener is in order? Because files in the book panel are opened by manually double clicking on said files (outside of a script of coarse).

My only other guesses were index, anyItem, itemByRange, but couldn’t figuring it out.

Adobe InDesign CS6 (8.0) Object Model JS: BookContent

Anyone else got a clue?

Thanks.

//#targetengine "BookOpenAll"

app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT; 

   

        //var sel=app.selection

        var doc;

        for( var i = app.activeBook.bookContents.length-1 ; i>=0 ; i-- )

            {

            app.open (app.activeBook.bookContents.fullName, true)

            };

       

app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;

Selected documents within a InDesign Book file/panel.

Screen Shot 2019-06-12 at 8.08.09 PM.png

TOPICS
Scripting

Views

2.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jun 12, 2019 Jun 12, 2019

Copy link to clipboard

Copied

It seems like I have to figure out how to get the specific names of the selected documents and then, the script will be able to open said documents afterward via itemsByRange?

But still it seems like the essential “connector” to getting those names is what is missing in all this. It’s like there is no “selected docs” or “highlighted doc” feature to speak to? It’s like that bridge is missing.

Unless I’m missing something.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jun 12, 2019 Jun 12, 2019

Copy link to clipboard

Copied

Attempted the below with eventListeners and itemByRange and got the below error.

Don’t know how to provide the ‘value’ it needs?

I feel like I’m close, but can’t bring it home.

//#targetengine "BookOpenAll"

app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;  

    

        //var sel=app.selection

        var doc;

        for( var i = app.activeBook.bookContents.length-1 ; i>=0 ; i-- )

            {

            app.open (app.activeBook.bookContents.eventListeners.itemByRange.fullName, true)

            };

        

app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;

Error generated from above code.

Screen Shot 2019-06-12 at 22.42.54.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jun 12, 2019 Jun 12, 2019

Copy link to clipboard

Copied

Forgot the parenthesis.

Man, what am I missing now (error prompt below)?

//#targetengine "BookOpenAll"

app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;  

    

        //var sel=app.selection

        var doc;

        for( var i = app.activeBook.bookContents.length-1 ; i>=0 ; i-- )

            {

            app.open (app.activeBook.bookContents.eventListeners.itemByRange().fullName, true)

            };

        

app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;

Now I’m getting the below error:

Screen Shot 2019-06-12 at 22.51.13.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jun 12, 2019 Jun 12, 2019

Copy link to clipboard

Copied

The below script operates fully, but not by what’s highlighted or selected in the indb, i.e. it still opens all docs in the book panel.

But funny thing is, it now starts from the top instead of the bottom (which I guess, if it’s not specified, it starts from the bottom by default). Ha.

Ay dios mios.

There’s still that illusive ‘select-these-specific-docs’ ‘based on the highlighted/selected docs’ displayed in the book file/panel component that’s missing from the below script.

Strangely, also, it cycles through the open documents multiple times for some reason.

//#targetengine "BookOpenAll"

app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;  

    

        //var sel=app.selection

var x=app.activeBook.bookContents.firstItem ()

var z=app.activeBook.bookContents.lastItem ()

        var doc;

        for( var i = app.activeBook.bookContents.length-1 ; i>=0 ; i-- )

            {

            app.open (app.activeBook.bookContents.eventListeners.itemByRange(x,z).fullName, true)

            };

        

app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 13, 2019 Jun 13, 2019

Copy link to clipboard

Copied

Neal, that is not how Event Listeners work ...

They only fire upon executing some actions, but not nearly all of the possible ones! If that was the case, then (1) yes, everything and anything can start a script – moving a mouse, pressing a key, selecting a guide line, et cetera – but … (2) InDesign, not the fastest software to begin with, would slow down to a glacial crawl, because for every possible action it then must check if there is an action attached to it.

As I understand it, only menus have actual event listeners attached to them: Indiscripts :: How to Implement a Basic Action Listener in InDesign. (Basically. There may be more but I haven't yet found a use for others than these.) Using Marc's ActionListener, I am able to catch all everything that can be executed through selecting a menu item, but nothing more than that. Selecting/deselecting a document inside the book panel is not a menu action.

This is the exact same "problem" (it's a limitation by design, so I hesitate to call it a "bug") as in previous questions asking how to get "the selected page in the Pages panel" and "the selected style in the Paragraph Styles panel". As with those questions, it's not an inherent property of the panel -- but it just may be possible to "get" what you want through a workaround.

Here is what I am thinking of:

In the Book  options, you can change the scope of preflightBookOptions  to "PREFLIGHT_SELECTED_DOCUMENTS" only. Choose a 'light' Preflight profile (or make one that does nothing) so it finishes quickly; then inspect its results.

However, I have an old script that works correctly with a single document, but at that point I'm stuck: I cannot readily find a way to add a preflightProcess to a book -- it seems "book.preflight()" works a bit different than for a single document.

Posting this anyway as it might give someone else an idea.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jun 13, 2019 Jun 13, 2019

Copy link to clipboard

Copied

So what you’re saying is the Indesign DOM doesn’t have any inherent “way” that’s accessible through scripting to account for current or active selections present in various panels, dialogues, etc.

Maybe the aforementioned preflightBookOptions results, as a string, can pass to firstItem and lastItem and then eventually to itemByRange (from the last posted script)?

Isn’t there a way to get the ‘results’ of a method/process, instead of having it actually carry out? Or per your suggestion, a lame-duck preflight job option can be set up. Whichever, but obviously getting the written results only is more appealing. But for now I would just settle for this working in any way.

It would also be great if it didn’t cycle through the docs multiple times after opening, but first let’s deal with the major goal. Ha.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jun 16, 2019 Jun 16, 2019

Copy link to clipboard

Copied

Jongware:

> As I understand it, only menus have actual event listeners attached to them

There are plenty more objects that can have event listeners, worth another look.

Neal, panel selections are not directly accessible by scripts, but a plugin can help with that. Back around CS3 when panels were introduced to scripting I abandoned such a plugin assuming Adobe would come around with a solution very soon. I've recently revived the project and while it is not ready for prime time, send me a PM with your email if you want to give it a try for your own use. Mac CC2019 only for now - I haven't touched Windows in years. See also screen shot below, the debugger is another project.

Screen Shot 2019-06-16 at 11.48.20.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jun 23, 2019 Jun 23, 2019

Copy link to clipboard

Copied

LATEST

I direct messaged you btw.

Looking forward to seeing if your plugin workaround does the trick.

Cheers.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 14, 2019 Jun 14, 2019

Copy link to clipboard

Copied

Hi Neal; you don't need a script file, select documents from book panel and double click.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jun 14, 2019 Jun 14, 2019

Copy link to clipboard

Copied

The original post failed to mention that the script also suppresses any prompts (fonts, images, etc).

Then it reactivates prompts, so they still appear when you close documents.

Funny thing is, I attempted to isolate out the prompt suppression aspect of the snippet (snippets below), but seems like those lines of code don’t work on prompts triggered by actions outside of the script itself, i.e. manual actions, i.e. double clicking on selected documents. So there must be some targeting issue that needs to be addressed, which I haven’t looked into yet.

Continually pressing ⌘. or, can help escape out of those prompts (also on close hitting D continually, i.e. Don’t Save helps escape out of save prompts on close, or just doing a Save All Open Documents ⇧⌥⌘S, first, before closing). But not having to pay attention to that on opening, to begin with, is preferable.

Thus the script.

//Disable Prompts

//app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;

//Suppress dialogues from interrupting script — per Peter Kahrel

app.scriptPreferences.userInteractionLevel =

UserInteractionLevels.neverInteract;

//Enable Prompts

//app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;

//Restore Interactive level — per Peter Kahrel

app.scriptPreferences.userInteractionLevel =

UserInteractionLevels.interactWithAll;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines