我想使用AppleScript和tag将指定标签分配给Finder(OS X 10.9.4)中的选定文件,但我在将文件路径传递给标签时遇到问题。用AppleScript更改Finder标签
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
如果我有/Users/fort/bar.txt
在Finder中选定的,我得到以下错误:
"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可以解析吗?谢谢。
堡
是确切的错误你是得到? – mcgrailm
我错误地添加了引号,并且我的Mac HD(这是MBA)的名称应该被预置为该路径。显然,文件名是由它组成的。所以,确切的错误应该是这样的:'tag:文件“MBA/Users/fort/bar.txt”无法打开,因为没有这样的文件。“ – fort