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…
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.
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?
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.
image-1.jpg
image-1-1.jpg
image-1-2.jpg
etc.
The Hazel log just shows PDFs being matched then moved. Successfully.
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.
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!