Skip to main content
Brian_Raila
Inspiring
June 8, 2022
Answered

TIMELY needing a Script which, upon Attached Document close, opens a Sibling Attached Document

  • June 8, 2022
  • 1 reply
  • 2545 views

 

I need execute precisely what the Subject states.

 

There is a document named Parent.pdf.  It contains two attachments – Son.pdf, and Daughter.pdf. [and Son.pdf is multi-page].  When Son.pdf is closed by user, Daughter.pdf is to open [in a new window, as set by its Initial View].

 

If Son.pdf is a single-page document, I can achieve the effect through its Page Properties, with Trigger: Page Close, Action: Go to a page view.  But this doesn't apply, as the user is to traverse multiple pages, prior to closing Son.pdf.

 

– – –

 

I have seen scripts to open an attachment by filename, but only as an Action of a Button Properties trigger [and while the parent document remains open].

 

I am aware of Document Actions, and Document JavaScripts [but only for setting a 'dirty file' state].

 

1.  Can this be achieved by a document-level script?

2.  Presumably nowhere else?

3.  Precisely what code is called for?  I have coded a modest amount, but have little intuitive guidance [beyond "don't be a sucker about case-sensitivity"].  My mastery of nomenclature, syntax, and punctation is limited.

 

Prompt replies shall be gratefully welcomed.

 

This topic has been closed for replies.
Correct answer try67

The openDoc command does not work when you try to place it in the Will Close event of a document (or as a doc-level script that executes when the document is opened), so no, this isn't possible to do automatically.

What you can do, though, is add a Close button to "Son.pdf", and have it execute this code:

 

var newPath = this.path.replace(this.documentFileName, "Daughter.pdf"); 
this.closeDoc(true);
app.openDoc(newPath);

 

When the user clicks it, the "Daughter.pdf" file will open, and "Son.pdf" will close (without saving -- remove the 'true' parameter from closeDoc to prompt the user to save the file, if needed).

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
June 8, 2022

The openDoc command does not work when you try to place it in the Will Close event of a document (or as a doc-level script that executes when the document is opened), so no, this isn't possible to do automatically.

What you can do, though, is add a Close button to "Son.pdf", and have it execute this code:

 

var newPath = this.path.replace(this.documentFileName, "Daughter.pdf"); 
this.closeDoc(true);
app.openDoc(newPath);

 

When the user clicks it, the "Daughter.pdf" file will open, and "Son.pdf" will close (without saving -- remove the 'true' parameter from closeDoc to prompt the user to save the file, if needed).

Brian_Raila
Inspiring
June 8, 2022

 

Thank you Gilad.  I've tested your suggestion; it works just as advertised.  Still not quite ideal though, insofar as:

  1.  The documents contain no JavaScript, thus not impeding the user who, either deliberately, or inadvertently, does not Enable Acrobat JavaScript.  My target audience are expected to be OK with Enable, but that's why I aked about a "nowhere else" solution [non-script].  This is merely a minor preference.  Of greater concern is

  2.  The narrative intent, in the story being told.  Daughter.pdf is to involuntarily appear upon closure, by whatever means, of Son.pdf.  In fact, the user is not even aware that Daughter.pdf exists.  When they're done with Son.pdf, they close it in their normal fashion [viewer window Close button, ⌘W, Menu Item>File>Close File].  Only then do they become aware of Daughter.pdf, who opens 'by surprise'.  She is indispensable, since verily 'tis she who tells the end of the story, and overall

  3.  The fewer buttons, the better.

 

Were I to use a button, I guess I could non-scriptly have the button Go to a page view' [opening Daughter.pdf], and 'Execute a menu item' to close Son.pdf?

 

Really the chief remaining difficulty is this:  The button works.  But the narrative is dependent on the user utilizing a button to Close Document, in a non-buttony storytelling landscape.  Above all, you can see this problematic scenario – the user is finished reading Son's tale, and closes Son's document.  Alas, Daughter never gets her say.  Thus the narrative never reaches its intended conclusion (leaving children around the world, to weep).

 

try67
Community Expert
Community Expert
June 8, 2022

If it's so essential the two files are read in sequence, why not combine them to a single file?