Macro Help - Selecting Specific JPG Files and Merging into PDF via Automator Action

Hi! I'm new to KM and am trying to set up a Macro that lets me quickly convert two or more images into one PDF file. I have an Automator action that does that via the Services menu, but I'd love to be able to have a one-key solution. I've tried setting it up in KM, but the PDF generated is blank. I'm not sure how to get the images selected.

What other information would you like from me? Thank you for your help!

Have you tried the KM Execute an Automator Workflow action?

If that does not solve your problem, please post your Macro and Automator Workflow. See:
How to post/upload your script/macro

Hi JMichaelTX. I have tried KM Execute an Automator Workflow. It created a PDF, but it was blank. The selected images were not in that PDF.

Here is the Automator Workflow:

Workflow received current [image files] in [Finder]

New PDF from Images
Save Output to: [Desktop]
Output File Name [Name Me!]
• Size Each Page to Fit

End of Automator Workflow

KM Macro:

Convert to PDF
This hot key: [F9] is pressed
Will execute the following actions:
Exceute "Convert to PDF" Automator Workflow
~/Dropbox/Convert to PDF.workflow

End of KM Macro

These two produce a PDF with the proper name, but the contents is blank, even when the images are selected prior to running the macro. It doesn't seem to matter where the actual Workflow file is located.

Running the workflow from the Services menu outputs the result (joined images into one PDF) correctly.

Thank you for your help!

Please post the actual Automator workflow file (zipped), and the actual KM macro file, using post/upload your script/macro.

Hi JMichaelTX,

Hopefully I did this right. I think I did. Thanks for your help!

Convert to PDF.kmmacros (1.4 KB)

Convert to PDF.zip (58.4 KB)

Thank you!

I use a combination of ImageMagick and pdfTK to accomplish this.

But it involves installing these 2 commandline tools.

Please reply if you are interested.

Hey @Athena,

it works fine when run from the Services menu, but it completely fails when run from Keyboard Maestro's Execute an Automator Workflow action.

Hey @peternlewis can you explain this?

I'm guessing the input is not passed to the Automator action when run outside the Services system – yes?

-Chris

Hey @Athena,

Okay, this is probably the simplest solution (barring miracles from Peter).

Put the Convert to PDF workflow where it's supposed to go:

~/Library/Services/Convert to PDF.workflow

Then use a macro like this to run it:

Convert Selected Images to a PDF File.kmmacros (6.0 KB)

I've added a Notification action to tell you the process is done and an Execute AppleScript action to reveal the newly created PDF file for renaming.

Jimmy's workflow will offer much more flexibility and customization, but this way is much simpler.

-Chris

1 Like

Hi Chris,

The actual workflow I call in the KM Macro is located inside the Services folder. It doesn't produce a PDF based on the selected images.

When run directly from the services menu, it produces the PDF as it should.

I'll give your suggestion a try and see what happens.

Thanks!

Hi Chris,

I downloaded and installed your Macro. I selected my images and ran the macro. I selected the two images and pressed the hotkey. One of the images was deselected. That's all that happened. No PDF, no Finder reveal. Did I miss something?

Thanks!

How does the Workflow get its input? Does it base it on the Finder selection? I would expect that to work from an Execute an Automator Workflow action. But if the input is from some other mechanism, that might be an issue.

Keyboard Maestro wont send any input to the workflow per se.

Hi Peter,

It's based on a Finder Selection. I select two or more images, right-click the mouse, and select "Convert to PDF" from the Services menu. It works perfectly when done this way.

When I open KM and assign a hotkey macro to run the Workflow, using Execute an Automator Workflow, a PDF is generated, but it's blank. The Finder selection is not used. The Automator Workflow I use in the macro is from the services menu. I've also tried using the exact same workflow placed elsewhere on the HDD. Same result. For some reason, the workflow is not run properly when invoked through KM.

The images are JPGs.

Thank you.

The Execute an Automator Workflow action is simply a wrapper to call the command /usr/bin/automator, so you could try using the Terminal and running the command:

/usr/bin/automator /path/to/your/workflow

See if it works and/or if it gives any indication of an error.

My guess would be that the system is blocking the access to the Finder Selection, maybe because of the new Automation permissions (check your System Preferences, Security & Privacy, Automation settings and see if there is anything there that looks like it needs adjusting).

Hey Peter,

Both of these fail on my system. (macOS Sierra 10.12.6)

image
image

With two test images @Athena sent me I get the same screwed up 896 byte file for output with each of those actions.

At least they're consistent.

In order to get this critter to run correctly I have to run it from the Services menu, and I'm doing that with a Keyboard Maestro Select or Show a Menu Item action in the Finder.

-Chris

If you open this workflow in Automator, and click the Run button, you get this warning:

I would guess that this “Quick Action” workflow is expecting to get its input as specified, but that that happens as part of the Finder/system running the workflow, not as part of the workflow itself being run, hence the warning and the behaviour.

I suggest you follow its instructions and create a new workflow, and add the Get Selected Finder Items action to the front, and that works fine in my tests.

Hey Peter,

Ah, so.

I seldom look at Automator, so I was missing the subtleties of this.

Thanks for scoping it out.

@Athena

I have created a new workflow like Peter describes.

Convert to PDF.workflow.zip (117.7 KB)

Convert Selected Images to a PDF File v1.02.kmmacros (6.9 KB)

-Chris

1 Like

Chris,

Your workflow worked great! The macro worked wonderfully! Thank you, everyone in this thread, for your help!

You guys are the BEST!

Thank you thank you!

1 Like

The KM macro (Convert Selected Images to a PDF File v1.02) is not working for me.

I tried to follow all instructions in this thread, but I still get a blank pdf whenever trigger the KM macro posted here. In all, I've tried the following:

  1. select images and run Convert to PDF.workflow from Automator
  2. select images and execute this line in Terminal: /usr/bin/automator /Users/tony/Library/Services/Convert\ to\ PDF.workflow
  3. select images and trigger KM macro (Convert Selected Images to a PDF File v1.02) using hotkey

Results
(1) produces the desired PDF from images
(2) and (3) produce blank pdfs
(2) gives error message: The action “New PDF from Images” was not supplied with the required data.

I also tried restarting with no change. I'm using an M1 Mac Air running KM 9.2 on Mac OS 11.5.2

Here are screenshots of the System Preferences settings mentioned by Peter and the dialogs I saw while doing all of the above. I granted permission in each case.

Thanks

Hey Tony,

That at least is promising.

I installed the workflow on my Mojave system, and it works perfectly.

My best suggestion for you is to:

  • Open the workflow in Automator.
  • Save As ⇢ New Workflow Name.
  • Replace the original workflow.

Unfortunately I don't have Apple Silicon or Big Sur to test with.

-Chris

Hi Tony. I'm attaching my Automator Workflow and KM macro. I'm using Big Sur, but not on an M1 Mac. I've confirmed them working on my system as of this morning. I hope they help.

Please reply if they don't and I'll try to assist.

Convert to PDF.workflow.zip (102.1 KB)

Convert to PDF.kmmacros (1.4 KB)

2 Likes