如何使用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
发布于 2011-06-24 10:55:26
更新:--我已经在CS5和MacOS10.7中测试了下面的代码,并且可以确认,即使简单地将tell application "Adobe Photoshop CS4"
切换到tell application "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的版本不会有太大的不同,如果有的话,因为已经很好地规范了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
https://stackoverflow.com/questions/6470379
复制