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

afterOpen event listener

Enthusiast ,
Apr 04, 2020 Apr 04, 2020

I'm sorry to asking this again.

But I never figured out how to deal with afterOpen event listener.

I know this event dispatches twice (on document openning and on window openning).

But even if I wrote my function to work on LayoutWindow target, it's running BEFORE the window is shown. I noticed that if I use InDesign's UI to open the file, the script runs wrong (BEFORE the layout window is shown). If I drag and drop a document to InDesign, the script runs fine. It also works fine if the document I'm openning is not the first one in InDesign.

 

Could anyone help me on this?

I need ro run my function AFTER the document window is shown.

var e = app.addEventListener("afterOpen" , main);

function main(ev) {
    if (ev.target instanceof LayoutWindow) {
        alert("Document window is shown");
        }
    }
TOPICS
Scripting
1.5K
Translate
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
Advisor ,
Apr 05, 2020 Apr 05, 2020

Hello,

Give the code below a try for you needs.

 

#targetengine "session"   
   
main();   
    
function main() {   
   app.addEventListener("afterOpen", myEventFunction, false);   
}   
function myEventFunction(myEvent) {   
     if  (myEvent.parent.constructor.name == 'LayoutWindow' ) {  
          
         alert( "Hello");  
     }  
  
} 

 

Regards,

Mike

Translate
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
Enthusiast ,
Apr 05, 2020 Apr 05, 2020

Same from my previous code.
If is the first document openning, the alert shows BEFORE the window shows.
If is the second+ document to be opened, the alert shows right.

If the document is dragged into InDesign, the alert shows right too.

Just goes wrong in the first openning. Which is exactly the case I need.

Translate
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
Advisor ,
Apr 05, 2020 Apr 05, 2020

It works fine for me as a startup script with Indesign 2020 on Mac OS Mojave 10.14.6.  What are you running?

I made a short .mov showing it work but I dont konw how to get it uploaded.

 

 

 

Regards,

Mike

Translate
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
Enthusiast ,
Apr 05, 2020 Apr 05, 2020
LATEST

I'm on Windows 10 and InDesign CC2020.

And, as always while developping, running the script from ESTK.

Maybe because of this?

I'll try to put it on the startup script.

 

Thank you so much!

 

// EDITED //
Not working even putting the script on the startup folder.

Translate
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