0

When viewing a file in Adobe Acrobat Pro XI on OSX Yosemite, I sometimes want to send the file to another application. To create an action in KeyboardMaestro, I need to get the path of the currently-open file from Acrobat. How can I get the path?

A way to send the value to the clipboard would be enough; getting a value I can manipulate in AppleScript would be even better.

1

So here's an AppleScript that I pasted together with the help of some other answers and the AppleScript reference. This puts the URL of the frontmost Acrobat document to the clipboard, e.g: file://localhost/Users/Your%20Username/Documents/Some%20Folder/Filename.pdf

 tell application "System Events"
        tell process "Acrobat"
            set thefile to value of attribute "AXDocument" of window 1
        end tell
    end tell
 set the clipboard to thefile
  • This works, but the use of the process name is problematic because it needs to be different for different versions of Acrobat. However, this was on the right path. I will post a variation that works in multiple versions of Acrobat Pro. – mhucka Oct 9 '17 at 15:34
1

Using in part the approach from this answer, I eventually developed the following bit of code. Note that this uses the application bundle id instead of the application name, so that it works in more versions of Acrobat Pro.

tell application "System Events"
    tell application id "com.adobe.Acrobat.Pro"
        set thefile to the file alias of the active doc
    end tell
end tell
set the clipboard to the POSIX path of thefile

Tested using Acrobat Pro (version 11) and Acrobat Pro DC (version 17).

  • user3439894 you're absolutely, my apologies, and thanks. – mhucka Oct 9 '17 at 16:22
1

This script will work with any application that has a “document one” open. I added a delay to the code which should give you enough time to bring your application with document one to the front.

You can also tweak the code to target Adobe Acrobat instead of front most application

delay 10 -- Gives You Time To Activate Whichever Application You Want This Code To Work For
tell application (path to frontmost application as text) to set the clipboard to (get path of document 1)

Before realizing that you came up with your own solution, I came up with another solution that works.

tell application "Adobe Acrobat Pro" to set the clipboard to the POSIX path of (get file alias of active doc)

This works for me using the latest version of Sierra and Acrobat Pro 10.1.1.33

  • This might work for some cases, but did not work for me in Acrobat Pro. It gives an error that it can't evaluate part of the expression. Its not clear to me why. Possibly a version difference, since I'm using Acrobat Pro and not regular Acrobat? – mhucka Oct 9 '17 at 15:36
0

In Acrobat, like in many applications, you can drag-and-drop the document icon from the window's title bar to other applications, which hands over the file's path (hold down the mouse button slightly longer before dragging). For example, if you drop the icon on the Desktop, the Finder creates an alias icon. If you drop it in a TextEdit document, the PDF is embedded in the text document, etc.

I'm not familiar with KeyboardMaestro, but I think it should be able to utilize this standard OS X feature somehow.

Otherwise you can still use OS X's Automator application and create a small application to drop the document icon onto (e.g. in the Dock) and send the file path to the clipboard. It's quite easy. The steps are:

  1. Open the Automator application.
  2. Choose to create a new Application.
  3. In the right-hand Actions pane, expand the Library and click Utilities.
  4. In the list of Actions, drag the action Copy to Clipboard into the left-hand assembly pane.
  5. Press CMD-S to save the new application, e.g., in the Applications folder.
  6. Drag the application icon into the Dock.

Done.

  • Thanks, but this is not at all what I'm seeking. I'm trying to get the path programmatically. The fact that I'm using KeyboardMaestro should have made that clear, but I also tagged the question with "applescript" and "script" ... – mhucka May 2 '16 at 19:46
0

(The manual way) Cmd-click (or right-click) the Acrobat window title and choose the parent folder. Open Terminal and drag the PDF-file into the terminal window. Copy the file path from the Terminal window.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .