使用AppleScript将标签设置为文件

gre*_*eth 3 macos terminal applescript label

我正在尝试使用以下代码在AppleScript文件上放置彩色标签:

set theFile to "HDD:Path:to:the:file.ext"

tell application "Finder"
    set label of file theFile to 3
end tell
Run Code Online (Sandbox Code Playgroud)

但是当我在终端中运行它时,osascript theScript.scpt我收到以下错误:

theScript.scpt:144:178:执行错误:Finder出错:无法将启动盘文件夹"Path"的文件夹"the"的文件夹"file.ext"的标签设置为3. (-10006)

任何想法,为什么我有一个问题,我怎么能让它工作?

mcg*_*ilm 7

它应该编码为a label index而不是a label,它需要是alias:

set theFile to "HDD:Path:to:the:file.ext" as alias
tell application "Finder" to set label index of theFile to 3
Run Code Online (Sandbox Code Playgroud)