Workaround for calling from InDesign on Mac Acrobat

With the help of @Test username and @Gilad D, I could get my original problem about 90% fixed.  Now, I need to tie everything together in order to solve this puzzle.  This puzzle called Acrobat from a script on Mac InDesign.

Windows users have no trouble because BridgeTalk is available for their use, allowing them to call Acrobat directly from InDesign script.  Mac users, on the other hand, have been cheated by Adobe.  BridgeTalk does not work with Acrobat on a Mac.  Unfortunately, where I work, I found myself in the unenviable position to require a script (written in JavaScript/ExtendScript) InDesign to call Acrobat to a simple page of replacement function.  And, of course, our computers here at work are all Macs.

With the help of the above, I, at least, got most of the way.  I discovered that AppleScript can be used to call Acrobat and do things.  And there is a 'doScript()' JavaScript function, which allows the scripts to another language to be run inside a JavaScript script.  Unfortunately, I ran into a wall when have AppleScript to save a file, but at least I can have call a function of the JavaScript script folder level to take care of her for me, I looked for work.  Yes, you can see the complications here.

So what must happen, then, is a JavaScript script that calls an AppleScript script which in turn calls another script JavaScript that runs inside Acrobat.  Phew!  Talk about a script-reception!  But I was actually able to make this work!  However, I ran into a little snag.

You see, I need to pass a variable through each of the three layers of scripts so that it works.  I'll post what I have so far.

First of all, the top-level script, which runs inside InDesign.  This is just a test script to make sure that it all works before I integrate it with the real InDesign script:

var fName = "testfile2.pdf";
var aFName = new Array;
aFName.push(fName);
scriptFile = new File ("/apache HD/Users/apache/Documents/unlockCover.applescript");
app.doScript(scriptFile, ScriptLanguage.APPLESCRIPT_LANGUAGE, aFName);

Now, the AppleScript file (the middle layer), you can see being referred to above:

on run argv
          set unlockedFile to item 1 of argv as text
          tell application "Adobe Acrobat Pro"
                    do script ("unlockCover(" & unlockedFile & ");")
          end tell
end run


This should, in theory, finally call the last script (low level), which is a JavaScript file saved inside the box at the level of the files for Acrobat, so that it runs automatically as soon as the launch of Acrobat and the function remains in memory to be called at any time:

var unlockCover = app.trustedFunction(function (fName)
{
          app.beginPriv();
          var myDoc = app.openDoc("/g/ ArtDept/Product Templates/ ProofCover/proof_cover.pdf");
          myDoc.replacePages(0, "/apache HD/Users/apache/Desktop/Old samples/407471 Folder/407471_cover.pdf", 0, 0);
          myDoc.saveAs("/apache HD/Users/apache/Desktop/" + fName);
          myDoc.closeDoc(true);
          app.endPriv();
});

There are the real meat of it.  These four lines between "app.beginPriv ();" and "app.endPriv ();" are those that this is all about.  However, I get an error message when I try to run the script at a higher level:

End of line but found consistent application or review.

If I send a call to each of you scripting gurus out there, how can I put the last nail in the coffin of this monster and call it a day.  I'm pretty sure 100% that the problem lies in trying to pass the argument ("aFName' in the top-level script) for the intermediate level AppleScript script.  Any ideas?

Problem solved.

I played with it a bit more and discovered that it was, indeed, passing the variable of AppleScript script that was the problem.  I used 'on run argv', I read on some site earlier today as the way AppleScript handles the arguments given.  More recently, however, I discovered that JavaScript uses a table defined as 'arguments' whenever AppleScript him passes a variable.  So, on a lark, I decided to try to use 'arguments' the other way ' round (I also had to add an extra set of quotes in the line "do script" AppleScript seems to save strings to variables without them):

set unlockedFile to item 1 of arguments
tell application "Adobe Acrobat Pro"
          do script ("unlockCover(\"" & unlockedFile & "\");")
end tell

And who did!  I can now pass a variable all the way from code JavaScript/ExtendScript InDesign JavaScript Acrobat low-level code top-level!  YAY!

Tags: Acrobat

Similar Questions

Maybe you are looking for