14 Replies Latest reply on Oct 8, 2013 6:51 PM by KenWK

    Batch Sequence with JavaScript

    KenWK Level 1

      Hi Guys,

       

      I have a batch sequence that won't save the original files. I'm getting a message "The file may be read-only, or another user may have it open. Please save the document with a different name or in a different folder."

       

      However, another batch sequence that runs on the same file saves it fine so I know that noone else has it open and that and I know I have rights to that folder.

       

      The sequence that won't save the file sets the open optons and has JavaScript in it that collapses the many bookmarks.

       

      Is there something about having JavaScript in the batch sequence that's not allowing this to save?

       

      Many thanks,

      Ken

        • 1. Re: Batch Sequence with JavaScript
          try67 MVP & Adobe Community Professional

          No, that shouldn't cause any such problems. Does it work if you save it

          under a different name?

          • 2. Re: Batch Sequence with JavaScript
            KenWK Level 1

            Yeah, sorry, I was just coming back to the post to add that but you beat me to it!

             

            Yes, it DOES work if I change the output options and add something to the beginning or the end of the filename.

             

            I also neglected to mention that I'm working in Acrobat 9 for this.

             

            It's making me crazy!

             

            Thanks a bunch for getting back!

            Ken

            • 3. Re: Batch Sequence with JavaScript
              try67 MVP & Adobe Community Professional

              Which OS?

               

              You can also save the file using JS, instead of via the built-in command in the batch sequence options.

              • 4. Re: Batch Sequence with JavaScript
                KenWK Level 1

                Windows 7 Pro.

                 

                Hmm, I've set the sequence to "Don't save changes" and added app.execMenuItem("Save"); to the end of the JavsScript, which runs last in the sequence, but it isn't saving the file.

                 

                Is there something other than app.execMenuItem("Save"); I should be using?

                 

                Thanks again,

                Ken

                • 5. Re: Batch Sequence with JavaScript
                  try67 MVP & Adobe Community Professional

                  First of all, make sure you update to the latest version available of

                  Acrobat 9. I think it's only officially compatible with Windows 7 from 9.2.

                   

                  Why did you do it like that? Why not use the built-in method of saving the

                  files at the end of the process?

                  • 6. Re: Batch Sequence with JavaScript
                    KenWK Level 1

                    Clueless, that's all. I've only ever written one or two JavaScripts.

                     

                    Should this.save(); be working because its not.

                     

                    The console is now opening everytime the sequence runs now also. What the heck is THAT about?!?!

                     

                    Oy.

                    • 7. Re: Batch Sequence with JavaScript
                      try67 MVP & Adobe Community Professional

                      this.save() is not a valid command, which could be why the console shows up...


                      As I said, use the built-in option to save the file (under the Output Options of the batch sequence), instead of trying to do it yourself in a script.

                      • 8. Re: Batch Sequence with JavaScript
                        KenWK Level 1

                        Well, I was getting the read-only message trying to use the save within the sequence (which is what my original post was) and you suggested trying it through the JavaScript. Right?

                         

                        Or have I completely lost it?

                        • 9. Re: Batch Sequence with JavaScript
                          try67 MVP & Adobe Community Professional

                          Sorry, I thought you had originally tried it with the execMenuItem command

                          when you were getting the read-only error...

                          The way to do it in JS is with this command:

                           

                          this.saveAs(this.path);

                          • 10. Re: Batch Sequence with JavaScript
                            KenWK Level 1

                            You rock!! That made it all go.

                             

                            I was mistaken befeore thought, its the JavaScript Editor that's coming up on the screen when I run the sequence. I have to close it with the OK button before the sequence finishes. It comes up for each file I process. Trouble is I can't imagine what I've changed that would cause that to start happening.

                             

                            The code looks like this:

                             

                            //Collapses all bookmarks and shows the bookmarks panel
                            function BookmarksCollapse(bkm, nLevel)
                            {
                            var s = "";
                            for (var i = 0; i < nLevel; i++);
                            bkm.open=0;
                            if (bkm.children != null)
                                for (var i = 0; i < bkm.children.length; i++)
                                    BookmarksCollapse(bkm.children[i], nLevel + 1);
                            }
                            BookmarksCollapse(this.bookmarkRoot, 0);
                            //app.execMenuItem("ShowHideNavigationPane");
                            //app.execMenuItem("ShowHideBookmarks");
                            this.saveAs(this.path);

                            • 11. Re: Batch Sequence with JavaScript
                              try67 MVP & Adobe Community Professional

                              You might have accidentally clicked the tiny icon next to the command, a small window icon. This causes the JS console window to open when each file is processed. Dumb, right? If that's the case, try clicking that icon again so that disappears and then run the batch again.

                              • 12. Re: Batch Sequence with JavaScript
                                gkaiseril MVP & Adobe Community Professional

                                If you are on a windows system make sure the Windows Explorer is not using the 'Preview" mode.

                                 

                                Are you on a network drive, then there could be clearing of the "Locked" status flag due to timing issues with the server or others may have the PDF open in an edit mode.

                                • 13. Re: Batch Sequence with JavaScript
                                  KenWK Level 1

                                  You were right Gilad, the "Interactive mode" was active. Yeah, kind of strange. Maybe its helpful for debugging in some situations?

                                   

                                  This now works as I need it to.

                                   

                                  Thanks very much for all your time.

                                  • 14. Re: Batch Sequence with JavaScript
                                    KenWK Level 1

                                    Almost forgot, GKaiseril, as I mentioned earlier, I know the network drive isn't a problem and the file is in a folder that is "mine." And while someone else could absolutely, potentially, open it I know it wasn't opened by someone else. I also have another sequence that runs fine on that same file, makes the changes and overwrites the original file.

                                     

                                    So, while the sequence is working great now I did have to do the save in the JavaScript as the sequence would only save the file to a different name and kicked a read-only error when trying to overwrite the original file.

                                     

                                    So, that part is still a mystery.

                                     

                                    Thanks again!

                                    Ken