Skip to main content
Inspiring
August 9, 2014
Answered

Indesign script to run on action?

  • August 9, 2014
  • 1 reply
  • 940 views

Hi, can anyone help - is it possible to set up an indesign script to be triggered to run on an action such as when you export to PDF (Instead of manually running the script)? To explain, I have a script that creates a text box to display the size of the indesign document, but if the page size changes the text box won't update unless you manually run the script again. so was wondering if it was possible to set the script to run when the document is exported to PDF, so in theory always being PDFd with the up to date pages size displayed!?

I might be approaching this whole problem from the wrong angle, as am quite new to scripting!!

Thanks in advance to any suggestions.

This topic has been closed for replies.
Correct answer Mrtreebis

Hi Trevor - thank you so much for this - (after a bit of trial and error with the edits!) managed to get it to work.

Job done, great stuff.

Thanks again

1 reply

Trevor:
Legend
August 11, 2014

Hi Mrtreebis

Edit the script below to suit your needs and  put it in the script startup folder.

In particular you need to edit the line app.doScript (line23) and put in the file location of the script you want to run.

Also if you only want the script to run  only with pdf exports then change line 14 to

if (!(/PDF/.test(ev.format)) || myExportEventHandler.pageDone) {

// Place the File in the Start Scripts Folder

// Example Simple eventListener for file exports by Trevor

#targetengine Trevor

function exportImportEventListener(){

    app.eventListeners.itemByName ("page range export").isValid && app.eventListeners.itemByName ("page range export").remove();

    app.addEventListener("beforeExport", myExportEventHandler).name = "page range export";

}

function myExportEventHandler(ev){

    // Stop the event bubbling recursively

    if (myExportEventHandler.pageDone) {

        delete myExportEventHandler.pageDone;

        return

    }

    // Stop the event from happening so we can change it.

    ev.stopPropagation();

    ev.preventDefault ();

    // DO YOUR MAGIC HERE

    app.doScript ('alert("Hi From Trevor")'); // CHANGE THIS LINE

    // Before restarting the event label it as done to prevent recursive problems

    myExportEventHandler.pageDone = true; // should really be called about to be done :-)

    // Restart the event

       fn = ev.fullName;

    app.activeDocument.exportFile (ev.format, ev.fullName, false);

}

exportImportEventListener();

// to remove the eventListener type in the ESTK app.eventListeners.itemByName ("page range export").remove();

MrtreebisAuthorCorrect answer
Inspiring
August 13, 2014

Hi Trevor - thank you so much for this - (after a bit of trial and error with the edits!) managed to get it to work.

Job done, great stuff.

Thanks again

Trevor:
Legend
August 14, 2014

Hi Mrtreebis,

Glad I helped.

Please can you mark the answer as correct.

Thanks

Trevor