News:

2023-03-15 Major improvements to the new Geolocation feature

Main Menu

(SOLVED) Accessing OSX file creation date (birth) with exiftool

Started by steinar, January 04, 2020, 05:22:05 PM

Previous topic - Next topic

steinar

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).
($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:

  • Is there any way exiftool can read this date, and how would I modify the command above to achieve it?
  • If not, can I combine the commands in a script and give exiftool a bash variable?

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"

StarGeek

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).

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.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

steinar

Fabulous! ;D It works like a charm. Thank you so much!