Rename file with least recent date found in file

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

Moderator: Mr_Noodle

I'm scanning a document that has multiple dates in the same format. I have a rule that looks for the nth occurrence of the date and then renames the file using that date, but I've found the OCR results are not always consistent. Sometimes the date I want is the first one found in a search, but sometimes it is the second or possibly even the third occurrence. The date I want to name the file with is always the least recent date in the file. Is there a way to create a rule to find the first 3 occurrences (or even all of them) in a certain format, and then name the file with the least recent date found?

Thanks for any suggestions!
tanglemac
 
Posts: 2
Joined: Sat Mar 26, 2016 10:22 pm

That would be very tricky, requiring multiple rules to compare all the different combinations. You would have one rule like "date1 is before date2" and "date1 is before date3" then <do something with date1>) and then likewise have separate rules for date2 and date3.

Alternatively, you can write a script.
Mr_Noodle
Site Admin
 
Posts: 11872
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Thanks for suggesting the script idea. I was able to get it to work by matching each of the first three dates into separate attributes and then passing those into this embedded applescript in the action section:

Code: Select all
set date1 to item 1 of inputAttributes
set date2 to item 2 of inputAttributes
set date3 to item 3 of inputAttributes
set oldestDate to date1
if date2 < oldestDate then
   set oldestDate to date2
end if
if date3 < oldestDate then
   set oldestDate to date3
end if
return {hazelOutputAttributes:{oldestDate}}

I then was able to name the file using the returned date value.
tanglemac
 
Posts: 2
Joined: Sat Mar 26, 2016 10:22 pm


Return to Support