bashmacosterminalspotlight

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


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


Solution

  • 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"