Skip to main content
Known Participant
March 15, 2012
Question

Closing library panels at beginQuit event

  • March 15, 2012
  • 1 reply
  • 1757 views

Hello,

I'm trying to have a javascript run when the user quits InDesign (CS5), and close all the Library Panels.

The code below (that only closes the Library Panels) works perfect if ran from ExtendScript.  But once I add the EventListener code and then place it in the startup scripts folder, it will loop but never close any panel.  I added the 'n' character so as not to get caught in the infinite loop.

I've also experimented trying to do this when InDesign is first launched, but it doesn't seem to work either.  I'm wondering if it has something to do with how events work in InDesign, and maybe the Library Panels aren't accessible at these points?

Any insight would be appreciated.  Thanks!

-------------------------------------------------------------------------------------------

app.addEventListener('beforeQuit', save_library, false);

function save_library(theEvent) {

    var n = 0;

    while(app.libraries.length > 0) {

        var lib = app.libraries[0];

        alert(lib.name);

        //lib.close();

        app.libraries[0].close();

        n++;

        if (n > 7) { break; }

    }

}

-------------------------------------------------------------------------------------------

This topic has been closed for replies.

1 reply

Loic.Aigon
Legend
March 16, 2012

Hi,

Why not use this line:

function save_library(theEvent) {

     app.libraries.everyItem().close();

}

But maybe the issue is that event may not allow application tweaks as it's about to close :S A 2cts thought.

Loic

thor2112Author
Known Participant
March 16, 2012

Hi Loic,

Thank you for your reply.  I gave your code a try, but when quitting the app, the Libraries still wouldn't close - which makes me think it's something with how the event works.

However, if I reverse things a bit, and run your code when the app first starts up, it works great!  I tried this originally with the code I had, but my code wouldn't work.  Running the code at startup (instead of at quit) will totally work for what I need, so thank you very much for sharing your code and thoughts.  I appreciate it!  :-)

Jay

March 12, 2013

Thor2112,

What does your final version of this script look like?

Thanks.

Matt