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


#1

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!


#2

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


#3

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!


#4

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


#5

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!


#6

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.


#7

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


#8

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


#9

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!


#10

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!


#11

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.


#12

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.


#13

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).


#14

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


#15

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.


#16

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


#17

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!