Created
July 4, 2020 01:48
-
-
Save gfxhacks/fcb46afdc8ed71f5885672cee6a35da8 to your computer and use it in GitHub Desktop.
Rename a file from a specified date metadata value in OSX. More info: https://gfxhacks.com/renaming-files-by-date-from-metadata
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#Cmd Usage: sh metaDateRenamer.sh file.ext kMDItemName | |
# Title: metaDateRenamer.sh | |
# Desc: Rename a file from a specified date metadata value. | |
# Author: gfxhacks.com | |
# More Info: https://gfxhacks.com/renaming-files-by-date-from-metadata | |
# kMDItem DATE descriptor options: | |
# Common Metadata Attributes: | |
# kMDItemContentCreationDate | |
# kMDItemContentModificationDate | |
# kMDItemAttributeChangeDate | |
# kMDItemLastUsedDate | |
# kMDItemDateAdded | |
# Audio Metadata Attributes: | |
# kMDItemRecordingDate | |
# Filesystem Metadata Attributes: | |
# kMDItemFSContentChangeDate | |
# kMDItemFSCreationDate | |
FILEPATH=`dirname "$1"` | |
FILENAME=`basename "$1"` | |
FILEEXT=`rev <<< "$1" | cut -d . -f 1 | rev` | |
# format date to: YYMMDDhhmm | |
DATETIME=`mdls -name "$2" "$1" | sed 's/[^0-9]//g' | cut -c 3-12` | |
echo "Rename to: " | |
read NAME | |
if [[ -f "$1" ]]; then | |
# copy and rename the specified file | |
cp "$FILEPATH/$FILENAME" "$FILEPATH/$NAME-$DATETIME.$FILEEXT" | |
# rename the specified file w/o copy | |
# mv "$FILEPATH/$FILENAME" "$FILEPATH/$NAME-$DATETIME.$FILEEXT" | |
else | |
echo "ERROR: File not found. Try again!" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment