Skip to content

Instantly share code, notes, and snippets.

@rommelfs
Last active December 25, 2015 06:49
Show Gist options
  • Save rommelfs/6935296 to your computer and use it in GitHub Desktop.
Save rommelfs/6935296 to your computer and use it in GitHub Desktop.
add information about file into metadata of file to be indexed by spotlight (OS X centric)
#!/bin/bash -x
FILENAME="$1"
echo "Collecting attributes for $FILENAME" &&\
HASHMD5=`md5 "$1" | cut -d"=" -s -f2|tr -d " "` &&\
echo -e "MD5\t\t$HASHMD5" &&\
HASHSHA1=`shasum "$1" | cut -d" " -f 1` &&\
echo -e "SHA1\t\t$HASHSHA1" &&\
SHA2ALGOS="224 256 384 512" &&\
HASHSHA2_224=`shasum -a 224 "$1"|cut -d" " -f1` &&\
echo -e "SHA2-224\t$HASHSHA2_224" &&\
HASHSHA2_256=`shasum -a 256 "$1"|cut -d" " -f1` &&\
echo -e "SHA2-256\t$HASHSHA2_256" &&\
HASHSHA2_384=`shasum -a 384 "$1"|cut -d" " -f1` &&\
echo -e "SHA2-384\t$HASHSHA2_384" &&\
HASHSHA2_512=`shasum -a 512 "$1"|cut -d" " -f1` &&\
echo -e "SHA2-512\t$HASHSHA2_512" &&\
MAGIC=`/usr/bin/file "$FILENAME"|cut -d":" -f 2|cut -d" " -f 2-` &&\
echo -e "Magic:\t\t$MAGIC" &&\
xattr -w com.apple.metadata:FILE_HASH_MD5 $HASHMD5 "$FILENAME" &&\
xattr -w com.apple.metadata:FILE_HASH_SHA1 $HASHSHA1 "$FILENAME" &&\
xattr -w com.apple.metadata:FILE_HASH_SHA2_224 $HASHSHA2_224 "$FILENAME" &&\
xattr -w com.apple.metadata:FILE_HASH_SHA2_256 $HASHSHA2_256 "$FILENAME" &&\
xattr -w com.apple.metadata:FILE_HASH_SHA2_384 $HASHSHA2_384 "$FILENAME" &&\
xattr -w com.apple.metadata:FILE_HASH_SHA2_512 $HASHSHA2_512 "$FILENAME" &&\
xattr -w com.apple.metadata:FILE_Magic "$MAGIC" "$FILENAME"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment