【问题标题】:Adding (Spotlight) comments to file using the command line in macOS在 macOS 中使用命令行向文件添加 (Spotlight) 注释
【发布时间】:2017-12-23 01:24:05
【问题描述】:

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

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

【问题讨论】:

    标签: bash macos terminal spotlight


    【解决方案1】:

    found 一个不错的 sn-p,适用于 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"
    

    【讨论】:

    • 不幸的是,这不再适用于 macOS 10.15 并引发错误:“osascript[53895:1841295] CFURLGetFSRef 传递了一个没有方案的 URL(该 URL 不适用于其他 CFURL 例程)” .如果有人对如何做到这一点有任何新的想法,那将是非常受欢迎的。
    • 也在寻找一种方法来做到这一点——@selfagency,你能找到解决方案吗?谢谢!
    【解决方案2】:
    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 验证。请注意,第一次执行此操作时会弹出一个安全对话框。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-12
      • 1970-01-01
      • 2013-04-11
      • 2022-06-23
      • 2011-12-31
      • 2012-10-06
      相关资源
      最近更新 更多