Jump to content

OCR, select the screen area, and press Enter to immediately obtain the text.


Recommended Posts

This is simple enough and looks quite ready to go in the Gallery, but I have a few suggestions:

  • You don’t need the Run Script, you can and should instead use the Run Shortcut automation. That would make it use no code and be a good candidate for the “Good for Learning” category.
  • Would be useful to add a Hotkey Trigger too. I can imagine someone using e.g. ⌘⇧6 to take the screenshot and get the text. By the way: nice use of the Automation Task.

Link to comment
On 2/15/2024 at 3:21 AM, vitor said:

This is simple enough and looks quite ready to go in the Gallery, but I have a few suggestions:

  • You don’t need the Run Script, you can and should instead use the Run Shortcut automation. That would make it use no code and be a good candidate for the “Good for Learning” category.
  • Would be useful to add a Hotkey Trigger too. I can imagine someone using e.g. ⌘⇧6 to take the screenshot and get the text. By the way: nice use of the Automation Task.

 

 

Thank you for your suggestion.


 

1. I have updated the workflow, have a try. 

2. because I change shortcuts, you must delete the OCR and then trigger the workflow.

3. I set Hotkey as ⌘ ⇧ 7 because the ⌘ ⇧ 6 conflicts with the system setting. Any user can customize the hotkey.

 

 

image.thumb.png.9ca6dc218c7d0bd2c96733f5d3e74e55.png

 

 

image.thumb.png.615a193e61bf68ad7279a3b812a4b553.png

Edited by Alan He
Link to comment
  • 1 month later...
  • 2 weeks later...
  • 1 month later...
1 hour ago, selfmade69 said:

Is it just me or this really require full swift command line tool to be downloaded and installed?

 

This workflow? It doesn’t, no.

 

1 hour ago, selfmade69 said:

Its taking some 24 plus hours downloading for the command line tool!

 

If it’s taking that long, there’s either a problem on your end of the connection or something went wrong on Apple’s side. I’d wager something hanged and would recommend restarting it.

Link to comment
On 2/17/2024 at 5:02 AM, Alan He said:

1. I have updated the workflow, have a try. 

Hi, @Alan He,

Thank you so much for this helpful workflow.

I have a query regarding its functionality. Is there a method to prevent the screenshot from being saved to the clipboard, retaining only the OCR text?

I attempted to disable the "Save to Clipboard" option within the "Interactive Screenshot" item, but it seems to result in an empty clipboard. Is there an alternative solution to achieve this?

 

Thank you again.

 

Link to comment
On 5/13/2024 at 5:41 AM, Faris Najem said:

Hi, @Alan He,

Thank you so much for this helpful workflow.

I have a query regarding its functionality. Is there a method to prevent the screenshot from being saved to the clipboard, retaining only the OCR text?

I attempted to disable the "Save to Clipboard" option within the "Interactive Screenshot" item, but it seems to result in an empty clipboard. Is there an alternative solution to achieve this?

 

Thank you again.

 

 

 

I think you have a point, but how to implement it I need to think about.

One way is that OCR here if I have to use the clipboard to pass the image then I can only script the deletion of the last image history after recognition.

Link to comment
8 hours ago, Alan He said:

then I can only script the deletion of the last image history after recognition.


I strongly advise against that. You should not be writing to Alfred’s clipboard database yourself, at the risk of corrupting it. If you don’t want the image in the clipboard at all, then save it to a file instead.

 

Having the image in the clipboard is not a major concern. Those don’t last long in the Clipboard History.

Link to comment
26 minutes ago, vitor said:


I strongly advise against that. You should not be writing to Alfred’s clipboard database yourself, at the risk of corrupting it. If you don’t want the image in the clipboard at all, then save it to a file instead.

 

Having the image in the clipboard is not a major concern. Those don’t last long in the Clipboard History.

Hmmm, it would be nice if there was a way to screen capture without putting it on the clipboard, that would be nice to control.

Link to comment
4 hours ago, Alan He said:

it would be nice if there was a way to screen capture without putting it on the clipboard

 

Like I said, save it to a file if you don’t want it on the clipboard, the Automation Task allows for that. Those are the two options; it has to go somewhere or it wouldn’t be useful. If you want it to save to the clipboard but not show up in Clipboard History, mark the data as concealed and Alfred by default won’t save it. In JavaScript for Automation it would be something like:

 

ObjC.import("AppKit")

function copySensitiveImage(imagePath) {
  const pboard = $.NSPasteboard.generalPasteboard
  const image = $.NSImage.alloc.initWithContentsOfFile(imagePath)

  pboard.clearContents
  pboard.setStringForType(undefined, "org.nspasteboard.ConcealedType")
  pboard.setDataForType(image.TIFFRepresentation, $.NSPasteboardTypeTIFF)
}

copySensitiveImage("/some/path/here")

 

But again, you should be saving it to a file instead.

Link to comment
Posted (edited)
On 5/14/2024 at 6:04 PM, vitor said:


I strongly advise against that. You should not be writing to Alfred’s clipboard database yourself, at the risk of corrupting it. If you don’t want the image in the clipboard at all, then save it to a file instead.

 

Having the image in the clipboard is not a major concern. Those don’t last long in the Clipboard History.

image.thumb.png.7cc28cf2e7d66e84c84bcc6c22fed25c.png

 

 

@vitor

Where to set store image to specified location ???? If you uncheck save to clipboard. Screenshots are stored on the desktop by default, which is definitely not appropriate. I need support for storing to a specific directory

 

Edited by Alan He
Link to comment

When saving as an image, the Automation Task outputs the path of the saved image as an argument to the next object. Connect something else to it (like a Move With the Finder Automation Task) to move it somewhere else. That Automation Task will also in turn return the destination path of the image. You can keep chaining as needed.

Link to comment
On 5/13/2024 at 5:41 AM, Faris Najem said:

Hi, @Alan He,

Thank you so much for this helpful workflow.

I have a query regarding its functionality. Is there a method to prevent the screenshot from being saved to the clipboard, retaining only the OCR text?

I attempted to disable the "Save to Clipboard" option within the "Interactive Screenshot" item, but it seems to result in an empty clipboard. Is there an alternative solution to achieve this?

 

Thank you again.

 

 

https://github.com/alanhg/alfred-workflows/tree/master/ocr

 

 

just have a try. v3

 

image.png.33cf63efe1d7ec4000ecfa02677262b9.png

 

 

No need to store screenshot to the clipboard when taking screenshot.

 

Link to comment

It seems that macOS 14.5 broke this and any other Shortcut that attempts to "Copy text from image".  If manually do a screenshot, select to grab text from image, select all, paste it works.  If I use your shortcut or any other that uses the same Shortcut actions they fail to actually extract the text. 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...