I download a lot of mp3 files containing pronunciation of words in a language I’ve been learning. I keep a record of these words and tag them appropriately using my hierarchical tagging system.
I’d like to download the files to a directory on the desktop. Keep them there for a few minutes until I’m done working with them, then import the file to DEVONthink Pro Office, tag the file there and delete the original.
Read on to see how the Hazel rule is written, including the AppleScript to make it happen.
The Hazel rule is simple:
- Look in a directory called “mp3”.
- Select files that have the mp3 extension.
- Allow the file to remain in place for 5 minutes
- Thereafter, execute the import and tagging script.
- Finally, delete the original file
Most of the action is in the AppleScript that provides a bridge from Hazel to DEVONthink.
AppleScript import action
Hazel exposes a variable
theFile that we can use as we import and tag the file. Here’s the entire AppleScript with comments following.
tell application id "com.devon-technologies.thinkpro2"
Line 2-3 - Launch DEVONthink and open the receiving database.
Line 4-5 - Reference the database by ID. There are other ways to do this. I just happened to find the ID in Script Debugger so I used it.
Line 7 - Set a reference to the destination group. Mine is
Line 8 - Perform the import returning the imported record. You can import without the return but then you would have to do extra work to find the file you want to tag.
Line 10 - Allow us to use a comma-delimited list of tags
Line 12 - Set the incoming file’s tags. Mine are as listed; yours would be something else.
Line 13 Restore the original text delimiters
That’s it! No you have a mechanism for automatically managing files from the Finder to DEVONthink.