Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

errors when getting selected text of preview pdf in automator

I want to get the selected text in preview app for a pdf file, so I wrote an service like below, want to get the selected text, and process in an AppleScript, but always got two error dialogs, no further information, (but it works well in Safari) Could someone give the help to fix it?


(the error picture is from another post, but my errors are same)


I found two posts about the same issue, but no final helpful answers, and I cannot reply in these posts.

Extracting selected text from PDF using A… - Apple Community

Automator workflow isn’t handing over sel… - Apple Community



MacBook Pro 13″, macOS 12.6

Posted on Sep 13, 2022 9:11 PM

Reply
Question marked as Best reply

Posted on Oct 4, 2022 12:55 PM

If you switch to the free Skim PDF reader, it will work with Automator Quick Actions and selected text in a PDF opened in Skim is passed into the Quick Action (input as text) when you choose the following setting:



Unless things have changed, Skim, like Preview, is written using Apple's PDFKit framework, witiout Preview's limitations, and with a strong AppleScript scripting dictionary supporting it.


I tested this with Skim v1.6.12 on macOS 12.6 just now and it works.

Similar questions

5 replies
Question marked as Best reply

Oct 4, 2022 12:55 PM in response to Peter_fan

If you switch to the free Skim PDF reader, it will work with Automator Quick Actions and selected text in a PDF opened in Skim is passed into the Quick Action (input as text) when you choose the following setting:



Unless things have changed, Skim, like Preview, is written using Apple's PDFKit framework, witiout Preview's limitations, and with a strong AppleScript scripting dictionary supporting it.


I tested this with Skim v1.6.12 on macOS 12.6 just now and it works.

Sep 16, 2022 2:24 PM in response to Peter_fan

The problem is not with your script, per se. It's with Preview.


For this, I'm assuming that your workflow headers are set to receive 'text' from 'Preview.app' (I don't read Chinese).


The problem is that Preview does not process text selection in PDF files in a way that makes sense to anyone out outside of Apple's developers - at least, it doesn't present the selected text to the workflow, so the workflow complains because it didn't receive any incoming text, so the rest of the workflow is moot.


You can confirm this by changing the headers to accept text from 'Any Application' rather than just Preview. Now you'll see it works.


The challenge you may have is that I don't see any way to get the selection in Preview.app. Based on the responses to the linked threads, it seems this may have changed over time, but as of right now, I can't see a way to do this with Preview.app.

errors when getting selected text of preview pdf in automator

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.