Page 1 of 1

Rename Images to Duration Between Two Dates (EXIF Tool)

PostPosted: Fri Mar 25, 2016 3:23 pm
by cfriend
Hi!

I'm loving Hazel so far and am having great success with the simple rules I've set up. My favorite so far is using the EXIF data to rename images in my Dropbox Camera Uploads folder. I'm doing that using this embedded script:

Code: Select all
exiftool -P -d '%Y-%m-%d %H.%M.%S' \
   '-filename<${FileModifyDate;}.%e' \
        '-filename<${GPSDateTime;}.%e' \
        '-filename<${MediaCreateDate;}.%e' \
        '-filename<${ModifyDate;}.%e' \
        '-filename<${DateTimeOriginal;}.%e' \
        "$1"


I don't know anything about bash/shell scripts, but I found that somewhere and it's working great.

Now what I'd like to do is set up a new rule that renames images based on the time between the Date Created and a specific date. The purpose is to drop "growth" photos of my dog into the "growth" folder and have hazel rename the photo "Dog at X.XX weeks" where X.XX is the number of weeks between the date created and 8/2/15, his birthday.

Can anyone help me do this? Thank you!

Re: Rename Images to Duration Between Two Dates (EXIF Tool)

PostPosted: Fri Mar 25, 2016 4:12 pm
by Mr_Noodle
This is beyond the support I can give but maybe someone else here will chime in. Doing date math may be a bit difficult with a shell script so it may be easier to do something like this in AppleScript.

Re: Rename Images to Duration Between Two Dates (EXIF Tool)

PostPosted: Fri Mar 25, 2016 4:33 pm
by cfriend
Mr_Noodle wrote:This is beyond the support I can give but maybe someone else here will chime in. Doing date math may be a bit difficult with a shell script so it may be easier to do something like this in AppleScript.


I don't know any AppleScript either but would welcome the challenge (with some help!) if that's the best way to go! Along with Hazel I've been using keyboard maestro as well; maybe between the three of them it is possible.

Thanks!

Re: Rename Images to Duration Between Two Dates (EXIF Tool)

PostPosted: Sun Apr 10, 2016 3:49 pm
by smm
Here is a script I use to calculate the difference between 2 dates. I saved it to a file with the name dateDiff, and then call it in a different script with:

dateDiff "<date1>" "<date2>"

alternatively, copy the code directly to your script, but replace "$1" and "$2" appropriately.

Note that this solution uses gdate (GNU date), but the source website utilizes date (the standard command). The source also describes a number of simpler but less generic methods to do date calculations.

Code: Select all
#!/bin/bash

# adapted from http://unix.stackexchange.com/questions/84381/how-to-compare-two-dates-in-a-shell

date2stamp () {
    gdate --utc --date "$1" +%s
}

case $1 in
   -s)   sec=1;      shift;;
   -m)   sec=60;     shift;;
   -h)   sec=3600;   shift;;
   -d)   sec=86400;  shift;;
   *)    sec=86400;;
esac
dte1=$(date2stamp "$1")
dte2=$(date2stamp "$2")
diffSec=$((dte2-dte1))
echo $((diffSec/sec))

Re: Rename Images to Duration Between Two Dates (EXIF Tool)

PostPosted: Fri Sep 23, 2016 6:37 pm
by Forlando952
This is a very important rule for hazel.
Please someone can explane the step of this rule
To get the difference of the date in a photo file?