Rename Images to Duration Between Two Dates (EXIF Tool)

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

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!
Last edited by cfriend on Thu Oct 06, 2016 4:22 pm, edited 1 time in total.
cfriend
 
Posts: 3
Joined: Fri Mar 25, 2016 3:11 pm

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.
Mr_Noodle
Site Admin
 
Posts: 11872
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

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!
cfriend
 
Posts: 3
Joined: Fri Mar 25, 2016 3:11 pm

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))
smm
 
Posts: 9
Joined: Sun Oct 25, 2015 10:28 am

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?
Forlando952
 
Posts: 8
Joined: Thu Jul 07, 2016 6:04 pm


Return to Support