如何获取当前打开的文件&x27;使用applescript在photoshop(cs5)中的路径?

如何获取当前打开的文件&x27;使用applescript在photoshop(cs5)中的路径?,applescript,photoshop,Applescript,Photoshop,如何使用applescript在photoshop(cs5)中获取当前打开的文件路径 我在MacOSX10.7上使用CS5 我尝试了下面的答案,但在Applescript编辑器中出现以下错误: error "Adobe Photoshop CS5 got an error: Can’t get document 1. Invalid index." number -1719 from document 1 更新:我已经在CS5和Mac OS 10.7中测试了下面的代码,并且可以确认,即使只需将

如何使用applescript在photoshop(cs5)中获取当前打开的文件路径

我在MacOSX10.7上使用CS5

我尝试了下面的答案,但在Applescript编辑器中出现以下错误:

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

更新:我已经在CS5和Mac OS 10.7中测试了下面的代码,并且可以确认,即使只需将
告诉应用程序“Adobe Photoshop CS4”
切换到
告诉应用程序“Adobe Photoshop CS5”
,也能正常工作。您得到的错误是由于您的目标是文档1,因此一开始没有打开文档。您可以通过以下方式轻松检查这一点:

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
旧答案:我还没有CS5,但这里是CS4版本,我想CS5的版本不会有太大的不同,如果有的话,因为Adobe在CS3之后已经很好地规范了API:

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

我在AdobeCS5和Lion上遇到了一些问题。这是它被记录的方式,但它不起作用。如果这对其他在Lion上使用CS5的人有效,请让我知道我是否需要在Photoshop或系统中检查任何设置。事实上,我打开了文档,所以这不是问题,但我猜Photoshop CS5中的Applescript有一个文件错误-你真的需要临时变量吗,或者您可以
返回文档1的文件路径吗?@tomlogic:不,不需要临时变量,但这不是重点。