Author Topic: (SOLVED) Accessing OSX file creation date (birth) with exiftool  (Read 931 times)

steinar

  • Newbie
  • *
  • Posts: 2
(SOLVED) Accessing OSX file creation date (birth) with exiftool
« 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).
($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

Code: [Select]
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"
« Last Edit: January 04, 2020, 05:59:02 PM by steinar »

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 5538
Re: Accessing OSX file creation date (birth) with exiftool
« Reply #1 on: January 04, 2020, 05:32:11 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.
Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If your GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.

steinar

  • Newbie
  • *
  • Posts: 2
Re: Accessing OSX file creation date (birth) with exiftool
« Reply #2 on: January 04, 2020, 05:58:42 PM »
Fabulous! ;D It works like a charm. Thank you so much!