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).
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"
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With