Last active
March 2, 2023 11:06
-
-
Save dnmellen/8300397 to your computer and use it in GitHub Desktop.
Revisions
-
dnmellen revised this gist
Jan 7, 2014 . 1 changed file with 8 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,13 @@ #!/usr/bin/python -tt """ Takes an screenshot (the user draws a rectangle to select the interesting area), scans the resulting image and copy the text to clipboard - scrot (http://en.wikipedia.org/wiki/Scrot) - readbot (`pip install readbot`) - pyperclip (`pip install pyperclip`) """ import sys import subprocess import pyperclip -
dnmellen created this gist
Jan 7, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,39 @@ #!/usr/bin/python -tt import sys import subprocess import pyperclip from readbot import ReadBot TEMPORARY_FILENAME = "/tmp/ocr_screenshot.png" def grab_screenshot(): """ Takes an screenshot and returns the saved file path """ try: retcode = subprocess.call('scrot -s ' + TEMPORARY_FILENAME, shell=True) if retcode == 0: return TEMPORARY_FILENAME except OSError as e: sys.stderr.write('Execution failed: ' + e) def image_to_clipboard(img_path): """ Given an screenshot copy text to clipboard """ if img_path: rb = ReadBot() text = rb.interpret(img_path) if text: pyperclip.copy(text) else: sys.stderr.write('No screenshot supplied') if __name__ == '__main__': image_to_clipboard(grab_screenshot())