使用AppleScript为文件设置标签 [英] Setting a label to a file with AppleScript
问题描述
我正在尝试使用AppleScript使用以下代码在文件上贴上彩色标签:
I'm trying to put a colored label on a file with AppleScript using the following code:
set theFile to "HDD:Path:to:the:file.ext"
tell application "Finder"
set label of file theFile to 3
end tell
但是当我在使用osascript theScript.scpt
的终端中运行它时,出现以下错误:
but when I run it in a terminal with osascript theScript.scpt
I get the following error:
theScript.scpt:144:178:执行错误:Finder出现错误:无法设置文件夹"the"的文档文件"file.ext"的标签 启动磁盘的路径"文件夹的"to"文件夹中的到"3.(-10006)
theScript.scpt:144:178: execution error: Finder got an error: Can't set label of document file "file.ext" of folder "the " of folder "to" of folder "Path" of startup disk to 3. (-10006)
关于我为什么有问题以及如何使其工作的任何想法?
Any ideas why I'm having an issue and how can I make it work?
推荐答案
应将其编码为label index
而不是label
,并且必须将其编码为alias
:
It should be coded as a label index
not a label
and it needs to be an alias
:
set theFile to "HDD:Path:to:the:file.ext" as alias
tell application "Finder" to set label index of theFile to 3
这篇关于使用AppleScript为文件设置标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!