6

Which command should I use to add a comment (from a file, or from the clipboard) to the 'Comments' section of a file (any file) in macOS?

These comments are used for Spotlight indexing and can obviously be added manually from the Finder (⌘+i), but for my purpose I want to be able to do it from the command line (to use in a Bash script).

Screenshot of Info dialog in macOS

Roel
  • 335
  • 1
  • 3
  • 10

2 Answers2

3

I found a nice snippet that works for me in 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"
Themerius
  • 1,861
  • 1
  • 19
  • 33
  • 1
    Unfortunately, this no longer works in macOS 10.15 and throws the error: "osascript[53895:1841295] CFURLGetFSRef was passed an URL which has no scheme (the URL will not work with other CFURL routines)". If anyone has any new ideas for how to do this, it would be most welcome. – selfagency Mar 31 '20 at 17:12
  • Also looking for a way to do this – @selfagency, were you able to find a solution? Thanks! – Carmen Sandoval May 01 '20 at 04:01
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"

Note the file:// URL prefix. Verified on 10.15.4. Note that you will get a pop-up security dialog the first time you do this.

dimo414
  • 47,227
  • 18
  • 148
  • 244
Wes
  • 950
  • 5
  • 12