Add a Prefix to the Currently Opened PDF File

Hi All,

On a daily basis, I receive a bunch of PDF files for review. I open all the files together as tabs, read thru the pdf and based on the content, I add a prefix "_" to the filename and then I move it to a subfolder.

I usually double-click on the file name on the Tab-bar, add the prefix and change the folder location, before clicking on OK.

I use the inbuilt Preview App or sometimes PDF Expert to read and rename the files.

Can this be converted to a script in Keyboard Maestro?

Thanks !

Hey Vinod,

Sure.

Is there only one level of subfolders?

-Chris

Hi Chris,

Yes. There is only one level of subfolder.

Regards,
Vinod

Hey Vinod,

Okay, that makes things simpler.

I don't have time at the moment to make this particularly pretty, but it works well on my macOS 10.12.6 Sierra system.

In Preview:

A) Run the macro (currently bound to the keyboard shortcut F1).
B) Enter your prefix text.

Screen Shot 2021-01-18 at 03.16.31

C) Select the subfolder you want to move your file to.

Screen Shot 2021-01-18 at 03.16.41

The document will close automatically, although that can be easily changed if needed.

This can be done entirely with Keyboard Maestro native actions, but it was quicker for me to do with AppleScript – which is why you have a solution tonight.

-Chris


Prefix the Name of the Front Document and Move it to a Chosen Subfolder v1.00.kmmacros (7.8 KB)

Hey Vinod,

I looked at PDF Expert and was a bit disappointed.

  • No AppleScript support at all.
  • No Rename Document command.
  • Accessibility does NOT include the path of the document.

It wouldn't be too hard to make a macro that works similarly to mine above though.

You'd have to:

I won't bother to do this, but I'm available for questions.

-Chris

Hey @ccstone,

it's possible to get a PDF Experts tab's path by using Accessibility and lsof.

See Script: Open DEVONthink record for PDF Expert tab - DEVONthink / Automation - DEVONtechnologies Community

Hope this helps.

1 Like

Hey Pete,

Clunky, but clever!  :sunglasses:

-Chris

1 Like

Hi Chris,

Thanks for the guidance. Based on the current feedback on PDF Expert, I have now moved back to Preview for viewing the PDFs.

My current workflow is:
-Receive 30-40 PDFs in the morning.
-Open all in Preview.
-Once I go thru the report and find no "further action required", I manually add a prefix "-" to the file name by clicking the filename on the tab-bar, else add " _ " to the file.
-Created an Automator script (Folder Action) which checks the file name. Those with "-" are moved to Trash; else " _ " emailed to my team for further action.

I'm currently trying to create a KM macro which can reduce the number of clicks for renaming (viz: CMD-T for adding a prefix "-" to the file and CMD-E to add "_".

Can you help me on the same?

Thanks,
Vinod

Hey Vinod,

These will work up though Mojave – beyond that I can't test.

You can change the prefix characters by changing the property prefixChar in the AppleScript.

-Chris


Preview ⇢ Prefix the Name of the PDF File Being Viewed with Space-Underscore_Space ⇢ “ _ ”.kmmacros (3.6 KB)

Preview ⇢ Prefix the Name of the PDF File Being Viewed with a Hyphen ⇢ “-”.kmmacros (3.6 KB)

@ccstone
What PDF editor app do you recommend?
I'm using PDF expert, but is not supported by Hook.app

I use Apple Preview for most things, and I have PDFpenPro for heavy lifting.

PDFpenPro is expensive (I got it on sale), but as far as I know it's the most scriptable PDF reader/editor available for the Mac.

** I just noticed that the PDF Expert demo made itself the default PDF viewer on my system without my permission. That's the kiss-of-death for me, unless the software is really useful.

-Chris

1 Like

Thanks!