ExifTool Forum

ExifTool => Newbies => Topic started by: steinar on January 04, 2020, 05:22:05 PM

Title: (SOLVED) Accessing OSX file creation date (birth) with exiftool
Post by: steinar on January 04, 2020, 05:22:05 PM
Disclaimer: I don't fully understand the commands I'm using, I've put them together based on things I've read on the forums here and on other sites.

For a while I have been using the command below to rename photos and videos automatically with Hazel (https://www.noodlesoft.com (https://www.noodlesoft.com)).
($1 is referencing the file being processed)

exiftool -P -d %y%m%d-%H%M%S \
'-filename<${FileModifyDate;}%-c.%e' \
'-filename<${GPSDateTime;}%-c.%e' \
'-filename<${MediaCreateDate;}%-c.%e' \
'-filename<${ModifyDate;}%-c.%e' \
'-filename<${CreateDate;}%-c.%e' \
'-filename<${datetimeoriginal}_${make}_${model;}%-c.%e' \
'-filename<${datetimeoriginal}-${subsectimeoriginal}_${make}_${model;}%-c.%e' \
'-filename<${datetimeoriginal}-${subsectimeoriginal}_${make}_${model}_${software;}%-c.%e' \
"$1"


Problem:
It works most of the time, but on occasion there won't be any DateTimeOriginal, CreateDate or MediaCreateDate, and the resulting filename doesn't reflect the creation date, but the file modification date (which is in the command as a failsafe). Mostly with video files. However in OSX I can still see the correct file creation date. OSX keeps track of the file creation date (birth date) separately, and I can access it with the bash command "stat" (see below)

stat -f "Access (atime): %Sa%nModify (mtime): %Sm%nChange (ctime): %Sc%nBirth  (Btime): %SB" file.txt

Access (atime): Nov 16 19:44:55 2017
Modify (mtime): Nov 16 19:44:25 2017
Change (ctime): Nov 16 19:44:48 2017
Birth  (Btime): Nov 16 19:44:05 2017


Questions:

Unsuccessful try:
I tried combining the stat command with the exiftool commands, but the code below did not work. (Again: $1 is referencing the file being processed)

date=$(stat -f "%SB" -t "%y%m%d-%H%M%S" "$1")

exiftool -P -d %y%m%d-%H%M%S \
'-filename<'"${date}"'-c.%e' \
'-filename<${datetimeoriginal}_${make}_${model;}%-c.%e' \
"$1"
Title: Re: Accessing OSX file creation date (birth) with exiftool
Post by: StarGeek on January 04, 2020, 05:32:11 PM
Quote from: steinar on January 04, 2020, 05:22:05 PM
Is there any way exiftool can read this date, and how would I modify the command above to achieve it?

I don't use a Mac but I believe it should be FileCreateDate, though the Mac filesystem does have a bunch of other tags (see MacOS tags (https://exiftool.org/TagNames/MacOS.html)).

Just copy the line that has FileModifyDate and replace that with FileCreateDate.  As to where to put it, you would have to decide it's priority.  If you decide it has priority over FileModifyDate, put it after that line.
Title: Re: Accessing OSX file creation date (birth) with exiftool
Post by: steinar on January 04, 2020, 05:58:42 PM
Fabulous! ;D It works like a charm. Thank you so much!