9 Replies Latest reply on Aug 8, 2008 4:04 AM by (Nethaji)

    How to access Acrobat menu using Applescript

      I'm new to AppleScripting but just don't get how to use the few Library commands available in Acrobat to do a fairly simple task. Maybe I'm expecting too much from AppleScript and this can't be accomplished:

      1. Open Acrobat 7.0 Professional (OK, got it)
      2. Open specific document (OK, got it)
      3. Go to Menu item "Document:Add Headers & Footers..." (?)
      4. Paste contents of Clipboard into center header (?)
      5. Close Window, Save Document (with same name), Close Document (?)

      Can this be done? Also, what are the Record and Stop buttons for in Script Editor? I haven't been able to find any info on these. I was hoping they worked like the old Excel Macro recording feature, but they don't seem to do anything. My OS is 10.4.11. Thank you for any help!
        • 1. Re: How to access Acrobat menu using Applescript
          Level 1
          Mike,

          For items 3 and 5 look at the doscript command. Something like this:

          --Code Start
          --Let Acrobat know that the script is beginning
          tell application "Adobe Acrobat 7.0 Professional"
          open "Macintosh HD:AGREEA.TIF" invisible "False"

          --Run the 'do script' command with the proper syntax
          (do script "app.execMenuItem('COMP:AddHeadFoot');")


          --Let Acrobat know that the script is ending
          end tell
          --Code End

          For item 4 your going to be relying on "System Events" to tab to the correct field and then paste the contents into that field.

          ~T
          • 2. Re: How to access Acrobat menu using Applescript
            Level 1
            Tembowa, thanks for your response! Where did you find the script "app.execMenuItem('COMP:AddHeadFoot');" ? Apparently I'm missing a lot here. This script does take me to the menu item i want (thank you), but you say I need to rely on "System Events" to do the tab and paste. What/where do I find how to use these events?

            mg
            • 3. Re: How to access Acrobat menu using Applescript
              (Aandi_Inston) Level 1
              When a menu item in Acrobat has a user interface, that is what you
              get. There is no way (in Acrobat's API) to suppress the dialog or
              provide data for it, though this may be possible at an OS level.

              You might be able to add text in other ways, though you cannot add
              regular page text.

              Aandi Inston
              • 4. Re: How to access Acrobat menu using Applescript
                Level 1
                Thanks Aandi. Instead of going to the Headers & Footers menu to paste in the text that's on the Clipboard, can I just paste the Clipboard text in the middle of the opened PDF document? This would work just as well for me.
                Thanks again.
                • 5. Re: How to access Acrobat menu using Applescript
                  (Aandi_Inston) Level 1
                  There is no function in Acrobat to paste text onto a page, except by
                  using the Text Touch Up tool (which has no API).

                  You can, however, add various kind of text annotation or form field
                  using JavaScript. You will need detailed reading of the Acrobat SDK,
                  you can't work effectively with Acrobat by browsing a dictionary.

                  Aandi Inston
                  • 6. Re: How to access Acrobat menu using Applescript
                    Level 1
                    It looks like I have to get involved with JavaScript. I guess I've got some reading to do...
                    Thanks again, Aandi!
                    • 7. Re: How to access Acrobat menu using Applescript
                      Level 1
                      Mike, I too was disappointed by what's included with the Applescript dictionary. So I tried to put together some handlers that gave me some of the extra things that are available to JavaScript (of which my knowledge is very little). The idea was to be able to construct Java Code Text on the fly then perform a do script with the result. You can add text to a document via the watermark from text. Here is where I got to with this function if it helps.
                      -------
                      property Default_Path : (path to desktop folder as Unicode text) as alias
                      --
                      set The_PDF to choose file of type "PDF " default location Default_Path ¬
                      with prompt "Where is the multi-page PDF?" without invisibles
                      --
                      tell application "Adobe Acrobat 7.0 Professional"
                      activate
                      open The_PDF
                      tell active doc
                      set The_String to "Mark Larsen"
                      my Add_WaterMarkText(The_String, 1, 1, 1, 1, 3, 0, 0, 0)
                      do script the result
                      close saving yes
                      end tell
                      end tell
                      --
                      on Add_WaterMarkText(cText, nS, nE, nTA, nHA, nVA, nHV, nVV, nR)
                      set Params to "cText: '" & cText & "'," & return
                      if class of nS is integer then set Params to Params & "nStart: " & (nS - 1) & "," & return
                      if class of nE is integer then set Params to Params & "nEnd: " & (nE - 1) & "," & return
                      -- 0 = left, 1 = centre, 2 = right
                      if class of nHA is integer then set Params to Params & "nHorizAlign: " & nHA & "," & return
                      -- 3 = top, 4 = bottom
                      if class of nVA is integer then set Params to Params & "nVertAlign: " & nVA & "," & return
                      -- offset in points
                      if class of nHV is integer then set Params to Params & "nHorizValue: " & nHV & "," & return
                      -- offset in points
                      if class of nVV is integer then set Params to Params & "nVertValue: " & nVV & "," & return
                      if class of nR is integer then set Params to Params & "nRotation: " & nR & "," & return
                      set JavaScript to "this.addWatermarkFromText({" & Params & "});"
                      return JavaScript
                      end Add_WaterMarkText
                      • 8. Re: How to access Acrobat menu using Applescript
                        Level 1
                        This utility may help if you are using System Events and AppleScript to execute menus without using the Acrobat APIs.

                        UIBrowser: http://prefabsoftware.com/uibrowser/

                        However, please note that this is by no means a panecea because not all of the menus that it will list actually work. It's a hit an miss functionality ... especially with Acrobat.

                        Sabian
                        • 9. Re: How to access Acrobat menu using Applescript
                          Hi Everyone,

                          We are using Acrobat 9.0 and we need to open Header and Footer or Watermark, Background dialog using VC++ code.

                          While Acrobat 7.0 or 8.0 is installed in the system the below code works fine:

                          menuItem = AVMenubarAcquireMenuItemByName( Header ,"COMP:AddHeadFoot" );

                          What should the "COMP:AddHeadFoot" value be if Acrobat 9.0 is installed in the system? The above code throws an error while executing in a system where Acrobat 9.0 is installed.

                          Regards,
                          Nethaji Harikriahna