这是我得到的,但我有一个带有“Active Projects”的自定义标签。 我如何分配?
告诉应用程序“Finder”将文件的标签索引设置为5
答案 0 :(得分:1)
你不能用香草AppleScript做到这一点。 Finder词典不支持添加标签。
但是,您可以使用AppleScriptObjC来访问Foundation框架
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
use framework "Foundation"
on addTagToPath(theTag, thePath)
set theURL to current application's NSURL's fileURLWithPath:thePath
set {success, tagArray, theError} to theURL's getResourceValue:(reference) forKey:(current application's NSURLTagNamesKey) |error|:(reference)
if theError is not missing value then error theError's localizedDescription() as text
if tagArray is not missing value and (tagArray's containsObject:theTag) as boolean is true then return
if tagArray is missing value then set tagArray to current application's NSMutableArray's array()
tagArray's addObject:theTag
set {success, theError} to theURL's setResourceValue:tagArray forKey:(current application's NSURLTagNamesKey) |error|:(reference)
if theError is not missing value then error theError's localizedDescription() as text
end addTagToPath
并使用它
try
addTagToPath("MyTag", "/Users/myUser/path/to/file.ext")
on error e
log e
end try
try
阻止了NSURL
方法