Skip to main content
SteveStrop
Known Participant
Aug 16, 2019 7:57 AM UTC
Question

How to wait for the "loaded" event in bridge extendscript?

According to the scripting guide:

A script should wait until the loaded event has occurred

before making calls to document selection methods.

Sounds good to me, but how do I "wait" for this event?

This topic is closed to new replies. Start a new post to keep the conversation going.

22 replies

SuperMerlin
Inspiring
Aug 16, 2019 9:06 AM UTC

Here is an example:-

onDocLoadEvent = function( event ){

if(event.object instanceof Document){

    if( event.type == "loaded" ){

          //Your code goes here

            }

        }

        return { handled: false };

}

app.eventHandlers.push( { handler: onDocLoadEvent} );

Translate
SteveStrop
Known Participant
Aug 16, 2019 9:49 AM UTC

I've tried that. Problem is the loaded event is occurs multiple times. I only want to run my code after the first time.

Translate
SuperMerlin
Inspiring
Aug 16, 2019 10:16 AM UTC

You could set a counter:-

app.eventHandlers.push( { handler: onDocLoadEvent} );

var count = 0;

function onDocLoadEvent( event ){

if(event.object instanceof Document &&  event.type == "loaded" ){

if(count == 0) doSomething();

count++;

    }

    return { handled: false};

};

function doSomething(){

    $.writeln("Got Here");

    }

Translate