Skip to content

Instantly share code, notes, and snippets.

@rommelfs
Last active December 25, 2015 06:49
Show Gist options
  • Save rommelfs/6935325 to your computer and use it in GitHub Desktop.
Save rommelfs/6935325 to your computer and use it in GitHub Desktop.
add comments to file in metadata to be indexed by spotlight (OS X centric)
#!/bin/bash
FILENAME="$1"
OLDCOMMENT="`mdls -r -nullMarker "" -n kMDItemFinderComment \"$FILENAME\"`"
echo "Old comment: $OLDCOMMENT"
while read LINE
do
COMMENT="$OLDCOMMENT $LINE"
done
echo "Updated comment: $COMMENT"
PATH=`pwd`
FULLPATH="$PATH/$FILENAME"
echo $FULLPATH
/usr/bin/osascript -e "set filepath to POSIX file \"$FULLPATH\"" \
-e "set the_File to filepath as alias" \
-e "tell application \"Finder\" to set the comment of the_File to \"$COMMENT\""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment