Skip to main content
Inspiring
September 25, 2024
Answered

Listen for imports in Indesign

  • September 25, 2024
  • 4 replies
  • 1146 views

I have an issue with a script I’m trying to develop. I’m using a third party app that allows the client to update tables, I import their changes into Indesign and then charts will get updated based on the updated tables. I have tried some event listeners to see what I would get. When I import the updates from the client an afterPlace is fired for each table that gets updated, also an afterImport would do the same. My issue is that I have no way of knowing when there are no more imports coming so I can begin the next part of the script, is there anything I can do?

Thank you

Alex

This topic has been closed for replies.
Correct answer rob day

Hi @Alex25077296wbvx , You should be able to do it by adding an idleTask, which takes a sleep parameter. You could set any amount of sleep time for it to trigger after the afterPlace event.

 

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#IdleTask.html

4 replies

Robert at ID-Tasker
Legend
September 25, 2024

@Alex25077296wbvx

 

If you import changes - then you should be able to know which table has been updated?

 

rob day
Community Expert
Community Expert
September 25, 2024

Here’s an example

 



#targetengine "placedone"

//add an afterplace listener
app.eventListeners.add("afterPlace", addIdle);
var iTask; 
var pc = false;

/**
* Add an idletask after the first place with a 2 sec sleep delay, adjust as needed
* @ param e the afterPlace event 
*/
function addIdle(e){
    if (!pc) {
        //make an idletask event with a 2 sec delay
        iTask = makeIdleTask("waitPlace", 2000);
        iTask.addEventListener(IdleEvent.ON_IDLE, placeDone);
        pc = true
    }
}

/**
* Alert 2 sec after last place and remove listeners
* @ param e idle event 
*/
function placeDone(e){
    alert("Place Done")
    //remove listeners
    app.removeEventListener("afterPlace", addIdle);
    app.idleTasks.itemByName("waitPlace").remove();
}

/**
* Makes a new named idleTask 
* @ param the task name 
* @ param the sleep time 
* @ return the named idleTask
*/
function makeIdleTask(n, s){
    if (app.idleTasks.itemByName(n).isValid) {
        return app.idleTasks.itemByName(n);
    } else {
        return app.idleTasks.add({name:n, sleep:s});
    }
}


 

 

 

 

 

Inspiring
September 26, 2024

This is a great suggestion I will give it a go. Thank you and thanks for all the suggestions this has been very helpful

Alex

rob day
Community Expert
rob dayCommunity ExpertCorrect answer
Community Expert
September 25, 2024

Hi @Alex25077296wbvx , You should be able to do it by adding an idleTask, which takes a sleep parameter. You could set any amount of sleep time for it to trigger after the afterPlace event.

 

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#IdleTask.html

leo.r
Community Expert
Community Expert
September 25, 2024

If I understand your situation correctly, then InDesign script functions won't help you here. You need to address this at your workflow management level. To have some kind of marker/event that indicates that no more imports are coming etc.