How can I get open file path in Photoshop (cs5) using applescript?

How can I get open file path in Photoshop (cs5) using applescript?

I am using CS5 on Mac OSX 10.7

I tried the answer below and it gives the following error in the Applescript editor:

error "Adobe Photoshop CS5 got an error: Can’t get document 1.
Invalid index." number -1719 from document 1
+5
source share
1 answer

UPDATE: I tested the code below in the CS5 and Mac OS 10.7 and can confirm that it works even with a simple switch tell application "Adobe Photoshop CS4"to tell application "Adobe Photoshop CS5". The error you get is the result of not opening the document at first because you are targeting document 1. You can easily verify this with the following:

tell application "Adobe Photoshop CS5"
    set documentCount to count documents
    if documentCount > 0 then
        set theDocument to document 1
        set theFilePath to file path of theDocument
        return theFilePath
    else
        -- no documents open. what to do?
    end if
end tell

OLD ANSWER: CS5 (), CS4, , CS5 , , Adobe , API CS3:

tell application "Adobe Photoshop CS4"
    set theDocument to document 1
    set theFilePath to file path of theDocument
    return theFilePath
end tell
--> Result: Macintosh HD:path:to:file:filename.ext
+2

All Articles