【发布时间】:2014-07-06 20:15:45
【问题描述】:
我想使用 AppleScript 和 tag 为 Finder (OS X 10.9.4) 中的选定文件分配特定标签,但在将文件路径传递给标签时遇到问题。
tell application "Finder"
try
repeat with currentFile in items of (get selection)
if label index of currentFile is 0 then
do shell script ("/usr/local/bin/tag -a 'foo' " & currentFile)
else
set label index of currentFile to 0
end if
end repeat
on error e
return e
end try
end tell
如果我在 Finder 中选择了/Users/fort/bar.txt,我会收到以下错误:
"tag: The file “/Users/fort/bar.txt” couldn’t be opened because there is no such file."
但是,以下代码确实将指定文件的标签更改为foo:
set myFile to "/Users/fort/bar.txt"
do shell script ("/usr/local/bin/tag -a 'foo' " & myFile)
知道为什么currentFile 没有以它可以解析的方式传递给tag 吗?谢谢。
堡垒
【问题讨论】:
-
这是你得到的确切错误吗?
-
我错误地添加了引号,并且我的 Mac HD 的名称(即 MBA)应该被添加到路径前。而且,显然,文件名是组成的。因此,确切的错误如下所示:
tag: The file “MBA/Users/fort/bar.txt” couldn’t be opened because there is no such file.
标签: tags applescript finder