1

I have an Automator service that accepts multiple pdf files, converts them to pngs while converting a white background to transparent, and then uses a Quartz filter to invert the color of the png file.

To test the workflow, I added the Get Selected Finder Items action to pass the pdfs to the service. Everything works exactly as expected in this case.

Service works when adding selected files in the workflow

However, when I remove this action, and then use the service from the Finder services, it does not work. All of the variables point to the correct files, but the bash script does not write any files, which can thus not be passed to the Quartz action.

Service does not work from Finder

Any ideas as to how to fix this?

[EDIT] I have added the warnings. I think this goes wrong because when running the workflow from Automator I cannot provide input the second way.

[EDIT 2] @boris42 pointed out that I did not add the requirement for the transparent background to my question, so I added it now.

Log for second method

2
  • Welcome to Ask Different! :) I noticed in your second screenshot there's a prompt at the bottom that you have two warnings. Can you edit your question to include what these warnings are?
    – Monomeeth
    Commented May 10, 2018 at 23:04
  • @Corollary Your warnings come from the use of set/get variables which you do not need. The data flow illustrated by arrows is not honoured in your case and warnings clarify that. However, Automator already has actions to do PDF-PNG and invert as well as copying, renaming and anything you might need without going to shell script or AppleScript.
    – boris42
    Commented May 11, 2018 at 14:48

2 Answers 2

0

Here is a simple Automator Finder Service that will do what I understand you're trying to do. It will render PDF pages with 200 dpi as PNG images then invert colours in them.

Automator PDF service

You will notice that I left the Show this action when workflow runs turned on so you can specify the folder you want the PNG files to be in.

Here is a test 3-page PDF file and the output this service generates:

test PDF

PNG files output:

PNG file output

3
  • Thank you for this suggestion. I already had a similar workflow, the only reason I use the script instead of the Preview action is that I want to be able to have white backgrounds from the pdf being transparent in the png. Using ImageMagick allows for this. Any idea why the script in my workflow does not output any results? Removing the variables and just passing through all the action outputs also does not work.
    – Corollary
    Commented May 12, 2018 at 11:35
  • @Corollary You are unnecessarily mixing AppleScript, shell script and Automator actions where the only thing needed to do would be to use shell where you convert PDF to PNG with IM and then use IM again to invert colours with -negate. The actual reason why your flow doesn't work is because you are passing string POSIX paths to Quartz action which expects file aliases.
    – boris42
    Commented May 12, 2018 at 12:45
  • @Corollary Your question says nothing about white needing to be transparent
    – boris42
    Commented May 12, 2018 at 12:46
0

Ok, after looking into this some more, it turned out to be a very silly mistake. My ImageMagick installation wasn't being found by my script. Adding the path solved the problem, and I was able to simplify everything a bit. This one works from the Finder Services and does exactly what I want. I was helped by this answer: https://apple.stackexchange.com/a/119109/288589

[EDIT] To get the right transparent background, as @boris42 mentioned, change the shell script to the new example.

Working solution with transparent background

2
  • Is there a reason why you don't do renaming and inverting colors (-negate in IM) in the shell script action? You can see the warnings in the log, right?
    – boris42
    Commented May 13, 2018 at 15:01
  • You are right, I did not mention the transparency in the main question, since I didn't want to complicate things. I should have been clearer, on second thought. Also, I do need a transparency command. It was working fine on my test cases since I already saved the PDFs with a transparent background. I have edited the answer to the actual solution for my use case. I will also edit the question for clarity. The warnings in the logs are only because the input isn't right when running from Automator, I think. When running from Finder, everything is OK.
    – Corollary
    Commented May 14, 2018 at 18:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .