使用 AppleScript 为文件设置标签 [英] Setting a label to a file with AppleScript

查看:28
本文介绍了使用 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 并且它需要是一个 别名:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆