SOLVED - Hazel/Shortcuts Combo Creating Multiple Duplicates

I need to extract JPGs from PDF files. So far it works, but it produces up to 32 duplicate JPGs for each original. My workflow looks something like this:

In Hazel - monitor <Folder 1> for PDF files. If found, then run the PDF2JPG shortcut

In Shortcuts

  • Get Contents of <Folder 1>
  • Repeat with each item
    • Make JPEG from Repeat Item
    • Save Image to <Folder 2>
  • End Repeat

Back in Hazel

  • Move to <Folder 3>

Everything ends up in the correct folder, but the Shortcut is running multiple times on each PDF file before Alfred moves it to the ‘done’ folder.

So I need to do some sort of ‘for each’ loop somewhere, but I can’t figure out how to do that in either Hazel or Shortcuts…

Feeling dumb…

Alfred does not have folder monitoring functionality. Could you be using folder actions or something like Hazel instead?

Chances are you have a timing issue somewhere between the monitor, the shortcut triggering, and the shortcut execution. But, potentially, your shortcut could also be a source of misconfiguration.

Please provide screenshots and/or an export of the configuration of your monitoring setup, and a link (not just a screenshot) of your shortcut.


Oh good grief. YES of course. Hazel. No access to laptop for a bit, will add more info later
(revised thread title and initial post)

Hazel rule:


Do keep in mind shortcuts are always best shared as links not screenshots - hence my explicit not above, but I don’t think there’s anywhere to go wrong in what’s shown.

What options have you got set in your Hazel rules two actions?

Do you have a difference in what happens if you add one PDF file vs several?

What version of Hazel are you running?

I know the JPEGs are duplicates but is their number equal to the number of pages in the PDF?

it might be trying, unsuccessfully, to export each page individually.

Related to this, is there any way to get a log of the Hazel actions?

In Hazel no options are set on the first rule. The second rule has the default ‘rename if exists’ but that only affects PDF files and there are no duplicates being created with those.
Adding one PDF at a time is fine. No duplicates.
I’m thinking the problem is that the shortcut just keeps running until Hazel moves the PDF. So I probably need a ‘do this only one time’ loop in the shortcut.

So if I have four images in a PDF, I get four JPEGs. Then I get 14-32 copies of each JPEG.
The Hazel log just shows PDFs being matched then moved. Successfully.

Okay, here’s what I think you have got set up:

  • When a PDF is added to a folder, Hazel matches rule criteria to it and triggers this processing.
  • The shortcut element is triggered by Hazel for each PDF.
  • The shortcut element runs against all available PDFs it finds currently in that folder.

In terms of what I think you therefore need to do:

What you need to do is to only process the matched PDF Hazel identifies with the shortcut rather than using Hazel to trigger a process for each match and having that process grab the set of all available PDFs. You need to process the PDF Hazel is matching rather than re-matching in Shortcuts.


1 Like

That did it!

Only one jpg for each embedded image.


Why the repeat loop if you only have one input item?

Oh. Yeah, that’s not needed now. Thanks.

Could you post a screenshot of the final shortcut (now that you have remove the Repeat action)? Specifically, I’m looking for what you now have as the object of the Make JPEG image action. Thanks!

It must be Shortcut Input.

Here - see if you can get this from an iCloud link: