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

2

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

Keirakeiser answered 18/7, 2017 at 9:11 Comment(0)
S
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"
Stillage answered 5/6, 2018 at 15:24 Comment(2)
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.Carboni
Also looking for a way to do this – @selfagency, were you able to find a solution? Thanks!Necessarily
W
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.

Wilburnwilburt answered 1/5, 2020 at 19:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.