Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the currently open file's path in photoshop (cs5) with applescript?

How can I get the currently open file's path in photoshop (cs5) with applescript?

I'm using CS5 on Mac OSX 10.7

I've 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
like image 864
cwd Avatar asked Jun 24 '11 15:06

cwd


1 Answers

UPDATE: I have tested the code below in CS5 and Mac OS 10.7 and can confirm that this works even with a simple switch of tell application "Adobe Photoshop CS4" to tell application "Adobe Photoshop CS5". The error that you are getting is the result of there either not being a document open in the first place since you are targeting document 1. You can easily check for 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: I don't have CS5 (yet), but here it is for CS4, and I imagine CS5's version won't be too different, if at all, since Adobe has done a good job normalizing the API since 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
like image 50
Philip Regan Avatar answered Nov 02 '22 15:11

Philip Regan