0

How do I set a spotlight comment for a folder using Bash. (Or Applescript)

The following example is not working:

osascript -e "tell application \"Finder\" to set comments of alias POSIX file \"$folder\" to \"This is a spotlight comment\"
Bruno
  • 127
  • 1
  • 8
  • Missing a close-quote on the command as typed. Is that how you were testing, or a transcription error? – beroe Feb 15 '16 at 06:03
  • 2
    Good spotting! Another crucial miss is the fact it needed to say comment instead of comments! – Bruno Feb 17 '16 at 22:48

1 Answers1

3

I modified this answer to be a function you can define in your ~/.bash_profile and it seems to work for files or folders:

makecomment(){
  osascript -e 'on run {f, c}' -e 'tell app "Finder" to set comment of (POSIX file f as alias) to c' -e end "$1" "$2"
}

USAGE:

makecomment foldername "My comment"
beroe
  • 1,147
  • 7
  • 18