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

Shortcuts.app Command Line Options

The Shortcuts app can be run from the CLI:


$ shortcuts run 'Extract Image Text' -i /Users/rich/Desktop/alpha.png -o /Users/rich/Desktop/imagetext.txt


However, the structure of the actual Shortcut is confusing. I want to run the script and copy the sniffed text into the clipboard for further processing. I don't know what instructions I need to get this done.


Right now I have Extract text from File and Copy Text from Image to clipboard however this doesn't seem to work, given the structure above:


$ shortcuts run 'Extract Image Text' -i /Users/rich/Desktop/alpha.png


Does anybody know how I have to structure this for it to grab the text?


Cheers

Posted on Apr 21, 2022 9:30 AM

Reply
Question marked as Best reply

Posted on Apr 22, 2022 8:14 AM

I started with a new Shortcut and initially added the Get Images from Input action. However, one must tell it that its images are obtained from the Shortcuts Input and not the default Input. When you click the blue Input item, you can then set it to the Shortcuts Input from the associated menu of input sources.


By making that change though, it prepends another action to Receive Any input from Nowhere. One must click Any and in the associated panel, click the Clear button to uncheck all input items and then reselect just the Images category. Now you have:



and then you append the next action Extract Text from Image, and the entire OCR workflow is in place:



This is what works in the command line example I provided earlier in this thread. I would run that initially without using the UNIX sed to see what your OCRed text looks like, and if the first line is a number, then use the sed syntax.


shortcuts run "OCR Image Text" -i $HOME/Pictures/OuterLimits.jpg --output-type public.utf8-plain-text -o - | sed '1d' | pbcopy


Similar questions

10 replies
Question marked as Best reply

Apr 22, 2022 8:14 AM in response to BioRich

I started with a new Shortcut and initially added the Get Images from Input action. However, one must tell it that its images are obtained from the Shortcuts Input and not the default Input. When you click the blue Input item, you can then set it to the Shortcuts Input from the associated menu of input sources.


By making that change though, it prepends another action to Receive Any input from Nowhere. One must click Any and in the associated panel, click the Clear button to uncheck all input items and then reselect just the Images category. Now you have:



and then you append the next action Extract Text from Image, and the entire OCR workflow is in place:



This is what works in the command line example I provided earlier in this thread. I would run that initially without using the UNIX sed to see what your OCRed text looks like, and if the first line is a number, then use the sed syntax.


shortcuts run "OCR Image Text" -i $HOME/Pictures/OuterLimits.jpg --output-type public.utf8-plain-text -o - | sed '1d' | pbcopy


Apr 21, 2022 12:22 PM in response to BioRich

Starting with this shortcut that I named OCR Image Text:



and this .jpg image:



I can run the following in the Terminal to OCR this input image and copy it to the clipboard:


shortcuts run "OCR Image Text" -i $HOME/Pictures/OuterLimits.jpg --output-type public.utf8-plain-text -o - | sed '1d' | pbcopy


I use sed to remove the first line on the clipboard which is the number 66 for some reason. If I want to see the text that was placed on the clipboard, I can output it back into the Terminal in lines that are 72 characters in width:


pbpaste | fmt -w 72



Apr 21, 2022 10:10 AM in response to BioRich

1) What is your mac model?


2) If one action produces text as output, you should be able to pipe it directly to pbcopy to get that text into the system clipboard, like this:


shortcuts run 'Extract Image Text' -i /Users/rich/Desktop/alpha.png | pbcopy


However, I cannot find 'Extract Image Text' in the Shortcuts application... is this perhaps only available in Apple Silicon macs, or was this downloaded from somewhere? Running the above example on my mac results in an error:


Error: The requested shortcut was not found


My mac is a 2019 16"MBP, and I can get text from images "manually"; but I read somewhere about this AI feature being exclusive to Apple Silicon (which clear it is not, at least not entirely).


Apr 21, 2022 3:33 PM in response to VikingOSX

That first input that you have, "Receive mages input from XXXXX" (can't read). I can't find that input. Can you explain how you built this?


I'm on Mac Mini M1. All the latest.


The manipulation of the text is, I'm assuming, taken care of. It's the submission of the files, through the CLI which is the issue right now.

Shortcuts.app Command Line Options

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