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

Close document inside aftersave event in jsx

New Here ,
Jan 30, 2017 Jan 30, 2017

Copy link to clipboard

Copied

Hi,

My goal : when the operator save his current document, I display my own screen (build in jsx) in which one of the options is 'close document'.

In the validate process, I detect the close option and call the jsx procedure document.close (), but this produce an error : impossible to close the document because I'm inside the event procedure. How can I solve this problem ?

BR,

Dominique

EDIT [moved by moderator to In Design Scripting]

TOPICS
Scripting

Views

548

Translate

Translate

Report

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
People's Champ ,
Jan 30, 2017 Jan 30, 2017

Copy link to clipboard

Copied

Are you using beforeSave of AfterSave ? If the former, you may prefer the latter.

Votes

Translate

Translate

Report

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
New Here ,
Jan 31, 2017 Jan 31, 2017

Copy link to clipboard

Copied

I use the afterSave event.

This what I did :

MyFunction ()

{

...

      dom.addEventListener("afterSave", SaveBdx);

...

}

function SaveBdx (docEvent)

{

...

if (reply == 1)

   dom.close ();

...

}

When executing dom.close (), I have the error : Close document impossible, because this is the target of an active event. 😞

Votes

Translate

Translate

Report

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 ,
Jan 31, 2017 Jan 31, 2017

Copy link to clipboard

Copied

if (reply!==1){ docEvent.preventDefault()}

Votes

Translate

Translate

Report

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
New Here ,
Jan 31, 2017 Jan 31, 2017

Copy link to clipboard

Copied

It doesn't work. I have got another error : 'impossible to cancel this event'.

May be I have to found a way to post a close event if the condition is valid.

Votes

Translate

Translate

Report

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
Guide ,
Jan 31, 2017 Jan 31, 2017

Copy link to clipboard

Copied

    docEvent.stopPropagation();

    docEvent.preventDefault();

Votes

Translate

Translate

Report

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
People's Champ ,
Jan 31, 2017 Jan 31, 2017

Copy link to clipboard

Copied

#targetengine 'onAfterSave'

var main = function() {

  var ev = app.eventListeners.itemByName ("onAfterSave");

  !ev.isValid && app.eventListeners.add ('afterSave', onAfterSave).name = "onAfterSave";

  function onAfterSave (evt) {

  var myIdleTask = app.idleTasks.item("afterSaveIdle");

  if ( !myIdleTask.isValid ) {

  app.idleTasks.add({name:"afterSaveIdle", sleep:100});

  }

  var onIdleEventListener = myIdleTask.addEventListener(IdleEvent.ON_IDLE, onIdleEventHandler, false);

  function onIdleEventHandler(myIdleEvent){

  myIdleEvent.parent.sleep = 0;

  var c = confirm ("Shall we close the doc ?", true, "What's next ?");

  c && evt.parent.close();

  }

  }

}

main();

Just wait for indesign to be idle

Loic

Ozalto | Productivity Oriented - Loïc Aigon

Votes

Translate

Translate

Report

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
New Here ,
Jan 31, 2017 Jan 31, 2017

Copy link to clipboard

Copied

LATEST

Thanks Loic.

It work fine with some adjustments.

BR,

Dominique

Votes

Translate

Translate

Report

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