在 macOS 中使用命令行向文件添加 (Spotlight) 注释

Adding (Spotlight) comments to file using the command line in macOS

我应该使用哪个命令将评论(从文件或剪贴板)添加到 macOS 中文件(任何文件)的 'Comments' 部分?

这些注释用于 Spotlight 索引,显然可以从 Finder (⌘+i) 手动添加,但出于我的目的,我希望能够从命令行执行此操作(在 Bash 脚本).

found 在 macOS 10.13 中对我有用的一个很好的片段:

osascript -e 'on run {f, c}' -e 'tell app "Finder" to set comment of (POSIX file f as alias) to c' -e end "/path/to/your.file" "hello world"
osascript -e 'on run {f, c}' -e 'tell app "Finder" to set comment of (POSIX file f as alias) to c' -e end file:///path/to/your.file "my comment blah blah"

注意 file:// URL 前缀。在 10.15.4 上验证。请注意,您第一次执行此操作时会弹出一个安全对话框。