23 Replies Latest reply on Nov 10, 2015 1:52 PM by Sturm359

    AppleScript doesn't understand how to save a document in Acrobat?

    Sturm359 Level 1

      Since BridgeTalk is out of the question, I've discovered that I should be able to use a doScript() command from my main InDesign script to call an AppleScript script which, in theory, can interface with Acrobat.

       

      However, I cannot even get the simple "save" command to work.  I input the code:

      tell application "Adobe Acrobat Pro"

                set templateFile to "/Volumes/g/ ArtDept/Product Templates/ ProofCover/proof_cover.pdf"

                set saveFilePath to "/Users/apache/Desktop/"

                set fileName to "407543_cover.pdf"

                set myDoc to open templateFile

                tell myDoc

                          save to file (saveFilePath & fileName)

                end tell

      end tell

      And the response I receive, after Acrobat opens the template file, is:

      AppleScript Error

      missing value doesn't understand the save message.

      What am I doing wrong?

        • 1. Re: AppleScript doesn't understand how to save a document in Acrobat?
          Test Screen Name Most Valuable Participant

          Are you trying to run this in an impersonal session (not logged on, web server, background task, whatever)? The reference to the apache user is alarming, is that the web server owner, or just a normal username?

          Is there really a space in the template file name?

          • 2. Re: AppleScript doesn't understand how to save a document in Acrobat?
            Sturm359 Level 1

            @Test Screen Name: Regarding your first sentence, I'm not sure I understand what you mean.  Not logged on to where?  The computer?  Absolutely, I am logged in to the computer.  There is no web server running on the computer that I am aware of, nor do I see what it has to do with this script.  And what background task are you referring to?  I have quite a few running, but they should not interfere with this script, as far as I can tell.

             

            Second sentence: I see your confusion, but the reference to 'apache' in the script is only the machine name and login name of this computer.  Our department's computers are named as such: "Apache", "Tomahawk", "Seneca", "Warrior", and "Navajo", which are the names of various aeroplane models.  So that line is only referencing the desktop of this computer.  Sorry for that confusion.

             

            Lastly, yes, there is a space in the template file name.  The template opens up perfectly fine in Acrobat when I execute the script, so there's no issues with that line.  The problem arises when the script attempts to save.

             

            Thanks for replying, @Test Screen Name.

            • 3. Re: AppleScript doesn't understand how to save a document in Acrobat?
              Test Screen Name Most Valuable Participant

              Yes, that was what worried me; Acrobat isn't for use on servers, but that doesn't apply.

               

              Are you referring to the Acrobat SDK for the AppleScript documentation? I haven't read it in many years, but there might be complications needed.

              • 4. Re: AppleScript doesn't understand how to save a document in Acrobat?
                Sturm359 Level 1

                I have not read the Acrobat SDK you mention, but would be interested in doing so.  Perhaps it might help.  So far, when googling the message I receive, most people seem to complain about a similar message, such as "document1 doesn't understand the save message."  Mine says 'missing value' instead of 'document1', which doubles the problems I'm having.

                • 5. Re: AppleScript doesn't understand how to save a document in Acrobat?
                  Test Screen Name Most Valuable Participant

                  The general rule is that to develop with Acrobat you need the SDK. Knowing common verbs, looking in dictionaries just doesn't give the full picture.

                   

                  You don't need the whole SDK, but here's the documentation

                  http://livedocs.adobe.com/acrobat_sdk/10/Acrobat10_HTMLHelp/wwhelp/wwhimpl/js/html/wwhelp. htm?&accessible=true

                   

                  You can tunnel to Acrobat Interapplication Communication > Interapplication Communication API Reference > Apple Event Objects and Apple Events

                  • 6. Re: AppleScript doesn't understand how to save a document in Acrobat?
                    Sturm359 Level 1

                    Okay, I'll check that out.  Now, my concern is: Does every computer that runs this script need to have the SDK installed?  If so, I might go a different route, if it works:

                     

                    Perhaps the Applescript could call a Javascript file that will run inside of Acrobat.  Would the SDK be needed for that, as well?

                    • 7. Re: AppleScript doesn't understand how to save a document in Acrobat?
                      Test Screen Name Most Valuable Participant

                      No, the SDK is essentially documentation. That's true with most SDKs, they provide the tools programmers need.

                       

                      What they will need, I imagine (but check the documentation) is Acrobat installed - not the free Adobe Reader.

                       

                      JavaScript is certainly an option. AppleScript has been frozen for well over 10 years, and may even have stopped working with nobody noticing. You CANNOT call JavaScript files, however.

                      • 8. Re: AppleScript doesn't understand how to save a document in Acrobat?
                        Sturm359 Level 1

                        Okay, that API reference is essentially the same information that I've gleaned from using the AppleScript Editor's Open Dictionary function.  No new information there, as far as I can tell, but I'll keep looking at it.  Also, all of our computers are using Acrobat X Pro, so no worries about that.

                         

                        If AppleScript cannot call JavaScript files, then that's a shame.  It means I HAVE to get AppleScript to work with Acrobat.  The reason I have to use AppleScript at all is because I have an ExtendScript script working in InDesign and I want it to call Acrobat to perform a quick page replacement.  Sadly, Adobe has not enabled BridgeTalk to work on Macs, so I have to use the workaround of using doScript() in my InDesign script to call the AppleScript script and have it run Acrobat's page replacement.  There's the background behind my conundrum.

                        • 9. Re: AppleScript doesn't understand how to save a document in Acrobat?
                          Test Screen Name Most Valuable Participant

                          Turns out I was mistaken. Acrobat on Windows can't be told to run a script from a file, but on Mac OS this is the way to run them (via AppleScript).

                           

                          You may also need to work with folder-level scripts. Be sure to read the JavaScript method documentation in detail, especially security notes.

                          • 10. Re: AppleScript doesn't understand how to save a document in Acrobat?
                            Sturm359 Level 1

                            From what I've read, folder-level scripts are ones that execute when Acrobat is launched.  Great for if you want to add a menu item to the program, but not so great for on-demand script launching, such as what I'm wanting to do: call Acrobat from an InDesign script to automate a task.

                             

                            I'm having issues withe security of which you speak, but since that's a separate problem from this one, I'll create a new topic for it.

                            • 11. Re: AppleScript doesn't understand how to save a document in Acrobat?
                              gkaiseril MVP & Adobe Community Professional

                              All folder level JavaScripts are syntax checked and tokenized when Acrobat is opened. All lines of script not within a function code block are executed. So function definitions are syntax checked and tokenized but not run unless specifically called.

                               

                              How to save a PDF with Acrobat 9 and JavaScript by Thom Parker

                               

                              You will have to adjust the folder location because of changes for Acrobat X and XI.

                              • 12. Re: AppleScript doesn't understand how to save a document in Acrobat?
                                Sturm359 Level 1

                                Does the folder-level script remain in memory?  If, for example, I have a function in the folder-level script that isn't called elsewhere in that same script, does it remain available to be called by a different script later on?  Perhaps with an argument passed to it by the calling script?

                                 

                                If not, then a folder-level script is useless to me.  As I said, I just want to automate a very simple task.  Here's a quick rundown:

                                 

                                1. InDesign script calls Acrobat (through AppleScript, since BridgeTalking with Acrobat doesn't function on Macs).
                                2. Acrobat opens a file on the server.
                                3. Acrobat replaces page 1 on the now-open document with page 1 from a specified file (passed to this Acrobat script from the InDesign script).
                                4. Acrobat saves this altered document to a specified location and with a specified name (also using the info passed from the InDesign script).
                                5. Acrobat closes the document.
                                6. Done.

                                 

                                Seems simple in theory:  Open a doc, replace a page, save the doc and close.

                                • 13. Re: AppleScript doesn't understand how to save a document in Acrobat?
                                  Test Screen Name Most Valuable Participant

                                  The folder level script is executed and discarded. But of course the things it defines, like functions, continue to exist.

                                   

                                  You are determined, it seems to me, to work via a route never envisaged by Adobe and which is going to cause more grief before it is over. Automating Acrobat from InDesign was not anyone's idea of what people would do.

                                   

                                  Is this, by the way, for a fully automated process, or does a user ultimately start this by clicking a button in InDesign?

                                  • 14. Re: AppleScript doesn't understand how to save a document in Acrobat?
                                    gkaiseril MVP & Adobe Community Professional

                                    The folder level script remains in memory as long as Acrobat/Reader remains open. This also applies to dynamic stamps. If a folder level script or dynamic stamp, one must close Acrobat/Reader and restart the application in order to see the changed script.

                                     

                                    The definition for a JavaScript function allows for optional parameters that are passed at the time the function is called.

                                     

                                    Any variable defined within a folder level script outside of the function remains active as long as Acrobat/Reader is active.

                                     

                                    Using the Acrobat JavaScript console. one can see the folder level scripts but not edit nor execute them. One can also see the various scripts within a form.

                                    • 15. Re: AppleScript doesn't understand how to save a document in Acrobat?
                                      Sturm359 Level 1

                                      Yes, if there's one thing I am, it's determined.  We have a certain workflow here at work that includes those steps I listed above, but in a manual fashion.  It gets tedious doing it sixty times a day.

                                       

                                      It won't be fully automated.  The InDesign script is initiated from the Scripts panel in InDesign (or hitting a keyboard shortcut that's been defined for that particular script).  At the end of all the stuff that InDesign does, I'd like it to call Acrobat to perform a page replace, then it's done.  Then the user grabs another job out of the inbox on his desk and repeats the process with it.

                                       

                                      I kinda like the idea that I'm twisting Adobe's scripting abilities to perform something they never envisioned, but that simplifies our art department's lives considerably.  Something I can add to my résumé.  ;~)

                                      • 16. Re: AppleScript doesn't understand how to save a document in Acrobat?
                                        Sturm359 Level 1

                                        @GKaiseril: Yes, I did get a folder-level script made.  It only contains four lines of code for now:

                                        function unlockCover ()

                                        {

                                                  app.openDoc("/Volumes/g/ ArtDept/Product Templates/ ProofCover/proof_cover.pdf");

                                        };

                                        And yes, there are spaces in that folder/filename.  I'm hoping to add to this after I make sure this passes 'the security test.'  Sadly, I just gave it a try and it failed.  I restarted Acrobat after putting the script in the correct location.  In Acrobat's Javascript console, I type the name of the function and it returns its contents, so I know that the function must still be in memory, as you have stated.  When I attempt to execute the function, however, I get the same security message as before.  What am I missing?

                                        • 17. Re: AppleScript doesn't understand how to save a document in Acrobat?
                                          Test Screen Name Most Valuable Participant

                                          This is heading in the right direction, except that it isn't a privileged script. Just putting it in a folder level script doesn't make it privileged (that would be very bad) but gives you the ability to use special calls (in the documentation) to make an ordinary script into a privileged one.

                                          • 18. Re: AppleScript doesn't understand how to save a document in Acrobat?
                                            Sturm359 Level 1

                                            Did a bit more research and found out about the app.trustedFunction() property, as well as the app.beginPriv() and app.endPriv() methods.  Came up with the following:

                                             

                                            var unlockCover = app.trustedFunction(function ()
                                            {
                                                      app.beginPriv();
                                                      // app.openDoc("/Volumes/g/ ArtDept/Product Templates/ ProofCover/proof_cover.pdf");
                                                      app.openDoc("/Users/apache/Desktop/407471.pdf");
                                                      app.endPriv();
                                            });
                                            

                                             

                                            Still getting the same security error message.  Tried with both versions of app.openDoc, just in case a file on the desktop would be different.  Nope.

                                            • 19. Re: AppleScript doesn't understand how to save a document in Acrobat?
                                              Test Screen Name Most Valuable Participant

                                              Let's take a step back. Are you absolutely sure it is the openDoc that is failing? (Not some later thing like replacing pages)

                                               

                                              Also (you may have said, sorry) what version of Acrobat is it?

                                              • 20. Re: AppleScript doesn't understand how to save a document in Acrobat?
                                                Sturm359 Level 1

                                                I haven't yet put in any code for replacing pages.  One thing at a time.  Just want to get Acrobat to open a document first, then I'll worry about replacing pages in it.  (Unless there's some way to replace pages in a document without opening it, but I doubt that.)

                                                 

                                                I'm using Acrobat X Pro, but we also have Acrobat 9 Pro on these Macs.

                                                • 21. Re: AppleScript doesn't understand how to save a document in Acrobat?
                                                  Sturm359 Level 1

                                                  Okay, so I've made a discovery.  I'm still relatively new to Macs and their file structure, so this one made me facepalm a bit.  It turns out that the filename I had going on ("/Users/apache/Desktop/407471.pdf") wasn't quite enough.  I had to add the hard drive in first, thusly: ("/apache HD/Users/apache/Desktop/407471.pdf").  When done this way, the script works perfectly.

                                                   

                                                  In fact, it even works in the Javascript console.  In further face, it even does so without the need for a folder-level script.  But that's not a concern at the moment.  The bottom line is that I have at least been able to get Acrobat to open a file, replace a page, then do a Save As command, then close the file.  All of this uses JavaScript, so it makes my original question about having AppleScript save an Acrobat document moot.  Thanks for all of the help; I'm now off to write a new post to ask about my current problem.

                                                  • 22. Re: AppleScript doesn't understand how to save a document in Acrobat?
                                                    Inyo55

                                                    In general, here is how to do it. You can modify the details.  It will work.

                                                     

                                                     

                                                    set myfile to choose file

                                                    set myfolder to "MyNewFolder" as text

                                                    set dpath to path to desktop

                                                    tell app "finder" to set thefolder to make new folder at dpath with properties {name:myfolder}

                                                     

                                                    set saveFile to (thefolder as text) & myfile

                                                     

                                                    tell application "Adobe Acrobat Pro"

                                                    activate

                                                    open myfile

                                                    <do something>

                                                    save document 1 to file saveFile

                                                    close document 1

                                                    end tell

                                                    • 23. Re: AppleScript doesn't understand how to save a document in Acrobat?
                                                      Sturm359 Level 1

                                                      Very cool. I see that my problem was probably the fact that I didn't include "document 1" in the line "save document 1 to file saveFile".

                                                       

                                                      I have no need to test this now, so I'm not sure if I should mark your answer as the correct one; I've gone a different route with our script since this discussion was held over two years ago. I've bent scripting to my will. I have a Java Swing program that calls the InDesign Javascript script, which eventually calls the AppleScript script, which calls another Javascript script inside of Acrobat. So, yeah, I had to make it layers deep, but it was the only way I could figure out how to get Acrobat to be run "inside" of an InDesign script (since BridgeTalk doesn't work between those two programs).

                                                       

                                                      That said, I'll definitely keep your solution in mind in case I need it in the future. Thanks, Inyo55!