Moving a file with Hazel based on characteristics found in another file?

I am editor for an academic journal and routinely download a manuscript file and a cover letter file. I would like Hazel (or some other automated process) to rename and move each file to a folder containing the manuscript ID which is contained in the manuscript file. Currently, Hazel recognizes the manuscript file, renames it, creates a folder, and moves the manuscript file to the newly created folder (see link below to the screenshot of the Hazel rule that works for the Manuscript file but, not for the cover letter file). However, the cover letter does not contain the same information as the manuscript file. Thus, I am unsure how to get Hazel to rename and move the cover letter file based on information in the manuscript file.

Example of Problem:

Manuscript File
Cover Letter (corresponding to the manuscript above)

Manuscript File is searched, renamed, and moved to a subfolder based on its attributes
Cover Letter is downloaded and triggered based on its attributes and needs to be moved to the same folder as Manuscript File (but this folder is different and depends on the attributes of File A)

See original rule for the manuscript file at this link (this rule does not incorporate File B but needs to):

https://www.dropbox.com/s/oq03jayall6g7cm/Screen%20Shot%202019-11-12%20at%201.40.58%20PM.png?dl=0

I have a bit of knowledge with AppleScript, own Keyboard Maestro, and TextExpander. Thus, I am happy to use any (or combination) of these tools to get the job done.

Any guidance on this problem is greatly appreciated.

@Brad,

Obviously the major issue you have is that Hazel does not provide a way of connecting the processing of two different files; as you know, each file is treated as its own separate entity.

I think there are a few ways of handling this, but all will essentially depend on there being some way of establishing a connection between the two files (M for the manuscript file and C for the cover letter file, to reduce typing).

Let’s assume that the files are connected via some sort of phrasing in the filename itself, eg M is called “-manuscript” and C is called “-cover letter”. In this case, the Hazel rule for the manuscript file can also execute an AppleScript; feed the manuscript ID as a variable into the AppleScript which then also moves the C file into proper subfolder.

Another option (which I would favor) is to do this particular operation in Keyboard Maestro. KM has th ability to watch folders, very similar to Hazel, but because you chain multiple scripting items together, you have KM find both the M and C files, get the manuscript ID from M, and use it to rename and file both of the files.

In short, the only way I can think for you to automate this process is that both M and C are going to have to have something in common that lets a script find the C file associated with a given M file. Once you have that in place, you can use Hazel or KM with a script action that uses the manuscript ID to rename and move the C file.

@nlippman,

Thanks so much for the fast and helpful reply. I thought of the KM option but, I did not know that KM can look in files and create variables from contents of the file (like Hazel is doing in this rule). I will investigate this option and report back. Thanks again!

@Brad:

Actually, I do not know of a mechanism for KM to look inside a file and create variables as Hazel can do. However, if the file contains interpretable text (eg if its a Word document, PDF with OCR layer, etc, then you can potentially use KM or command line tools (grep, etc) to find the necessary information and store it in a KM variable.

1 Like