Keyboard Maestro Macro to quickly copy the name of a similar file

Hey there,

I use DEVONthink mainly to file my documents. A really nice feature is that DEVONthink AI shows me all related files. (The lower part in the right pane named See also & classify)


In this example I need to rename file A and used the lower right pane to check that it should be renamed similar to file B.

So I wrote a macro to quickly copy the filename of file B then (optionally modify it) and then paste it to file A and make sure that the preview window will show file A again.

Without the macro to copy the name I’d have to right click the file, then click Get info “wait” for the popup to open and the text to be selected. Then copy it using Cmd+C, dismiss the popup and then select the initial file again (to see the correct date) and rename it using Enter & Cmd+V.

Over the holidays I sat down to automate these steps with Keyboard Maestro so it’s now only one keystroke to

  • get the name of the current item in the preview
  • remove the date prefix
  • reselect the initial file in the preview
  • paste the filename with the cursor where the date should go.

The macro doesn’t use any click events or similar things. It just works with menu bar items so it should be very stable but needs to be adjusted for other localizations than EN.

Please let me know if it is of any help for you or if you have suggestions :slight_smile:

Cheers Jan

Copy filename.kmmacros.zip (3.7 KB)
Notes for potential adjustments:

  • I use the file format yyyy_mm_dd .* in case you format your dates differently you need to change Assert that filename was retrieved and Remove date from filename.
  • I use a prefix of - as indicator for Hazel to assume a shorter date format and -- to find a date from the content of the file. You’d probably want to change Remove date from filename and disable Select -- Prefix.
  • I like to have the pasted filename in the clipboard history. Otherwise you can enable Delete Current System Clipboard.
2 Likes

Thanks for sharing!

  • Can you provide example filenames, before and after?
  • And are you processing specific kinds of documents, e.g., PDFs, ?

I’ve updated the post and title a bit.

The macro works for every file of any format. I use it for pdfs but you could also adjust it for a Zettelkasten or academic papers.
It shines when you often have items with similar names where only a specific part of the name needs to be changed. Most likely a date but could also be an ID or version.

It can be used for any task where you’d want to copy the filename of file B (in the image) and paste it to the file A. Or you could disable a few steps and just copy the name.

I use it to rename an scanned file to a similar file.
So I might see and select 2023_01_03 Insurance yearly information in the lower right pane and press the shortcut to prefill the scanned files name with -- Insurance yearly information and having the cursor where I need to insert the date.

As I wrote it assumes the date format yyyy_MM_dd at the beginning of the file and also the -- is specific to my usage of Hazel. But I kept it as a template for others to adjust to their file format/usage.

But why should it be renamed with file B’s name?

Not with the filename but similar.
So in my case it’s often the case that I have 2023_01_03 Insurance yearly information in the db and then get a new file which should be named 2024_01_05 Insurance yearly information or 2023_02_21 Insurance summary.

This is fantastic. I have exactly the same use case for labeling yearly insurance policy statements and the like.
Thank you for sharing it.

1 Like