F1 Import- Is there a way to chain to a custom script - change file creation date?

I really like EagleFiler and am having success using it with Hazel to automate a lot of the effort of my paperless office.

My workflow includes scanning documents to a temporary intermediate folder using Scansnap, then automatic OCR conversion with AABBYY Finereader.

After that, the file sits in the temporary, intermediate folder. If it’s a file I’ve scanned previously and often, like a bank statement, I next drag the file into a subfolder where Hazel picks it up, runs preconfigured recognition rules and then tags it and imports it into the right folder in EagleFiler.

But some files are unique “one-ofs” and I don’t have Hazel rules for them. For these files I use the eminently handy “Function-Option F1” key to manually import into Eagle Filer.

This all works quit well, but I’d like to improve the workflow for manual imports. My Hazel rules for recognized files all include a script to change the creation date based on the filename. By convention, I’ve configured Scansnap to name all scanned files by prepending the file name today’s date: 2016-09-04–FileName here.pdf. Then I manually change the date to the actua creation date (the date on the document).

My script reads the date at the beginning of the filename, and changes the “Creation Date” to the date in the filename and then renames the file to prepend the creation date in front of the filename. This allows me to file my documents weeks later, and still have the file creation date be equal to the date of the bank statement.

But when I invoke the F1 key, I’m so far, unable to run my script as part of the import process.

Is there a way to intercept/edit the script that is run when the F1 key is used to manually import a file into eagleFiler? Or to chain to another script to change the file creation date based on the file name?

Here is the script I use to alter the creation date.

# Take filename, YYYY-MM-DD--New Name.pdf and
# - adjust the creation date using /usr/bin/setfile -d
# - adjust the modification date using /usr/bin/touch
# - rename the file to New Name.pdf using /bin/mv
 
filename_without_path=$(basename "$1")
extension="${filename_without_path##*.}"
filename_without_extension_or_path="${filename_without_path%.*}"

YYYY=$(echo "$filename_without_extension_or_path" | awk -F "-" '{print $1}')
MM=$(echo "$filename_without_extension_or_path" | awk -F "-" '{print $2}')
DD=$(echo "$filename_without_extension_or_path" | awk -F "-" '{print $3}')
NNAME=$(echo "$filename_without_extension_or_path" | awk -F "--" '{print $4}')

# Change creation date
/usr/bin/setfile -d "$MM/$DD/$YYYY" "$1"
# Change modification date to Today/Now
# /usr/bin/touch "$1"
# Rename file
# /bin/mv "$1" "$NNAME"

Several options:

  1. If you are always in the same app when you press the capture key, you could override the capture script for that app by creating your own script with the bundle identifier for that app.

  2. You could create a new script that processes the file and then uses:

tell application "EagleFiler"
    capture with asking for options
end tell

to run the regular capture script and options window.

  1. You could create a new script that processes the file and then passes it to:
tell application "EagleFiler"
    import files {_path} with asking for options
end tell

to import it using the options window.

Or you could import the file into EagleFiler first and then use a script like this to alter the creation dates of the selected files. Or use a script like that combined with this:

tell application "EagleFiler"
    set _records to import files {_path} with asking for options
    -- alter creation dates of _records
end tell

to alter the creation dates of the imported records.