Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 844
Roel Avatar asked Oct 17 '22 09:10

Roel


2 Answers

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"
like image 56
Themerius Avatar answered Oct 20 '22 09:10

Themerius


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.

like image 23
Wes Avatar answered Oct 20 '22 10:10

Wes