Last active
March 12, 2019 06:01
-
-
Save nacookan/a35c04790733c4c8651978e59cad23f3 to your computer and use it in GitHub Desktop.
cmd+shift+control+4で範囲選択スクショを撮ると自動でOCRした文字列をクリップボードにコピーする(Mac用)
This file contains 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 characters
#! /usr/bin/ruby | |
# brew install tesseract | |
# brew install pngpaste | |
require 'tempfile' | |
loop do | |
Tempfile.open do |img| | |
if system("pngpaste '#{img.path}' 2> /dev/null") | |
Tempfile.open do |res| | |
system("tesseract '#{img.path}' '#{res.path}' 2> /dev/null") | |
system("cat '#{res.path}.txt' | ruby -pe '$_.rstrip! << \"\n\"' | grep -v '^\s*$' | pbcopy") | |
print `pbpaste` | |
end | |
end | |
end | |
sleep 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment