以下是一个使用绝对路径设置Finder标签的AppleScript示例代码:
-- 设置要添加标签的文件的绝对路径
set filePath to "/Users/your-username/Documents/example.txt"
-- 检查文件是否存在
tell application "Finder"
if not (exists file filePath) then
display dialog "文件不存在。"
return
end if
-- 获取文件的POSIX路径
set posixPath to POSIX path of filePath
-- 设置文件的标签
set tags of alias posixPath to {"Red"} -- 将标签更改为你想要的颜色
-- 显示成功消息
display dialog "标签已设置。"
end tell
请确保将your-username
替换为你的用户名,并将filePath
更改为要设置标签的文件的绝对路径。在上面的示例中,标签颜色被更改为"Red",你可以根据需要更改它。