Skip to content

Instantly share code, notes, and snippets.

@nacookan
Last active March 12, 2019 06:01
Show Gist options
  • Save nacookan/a35c04790733c4c8651978e59cad23f3 to your computer and use it in GitHub Desktop.
Save nacookan/a35c04790733c4c8651978e59cad23f3 to your computer and use it in GitHub Desktop.
cmd+shift+control+4で範囲選択スクショを撮ると自動でOCRした文字列をクリップボードにコピーする(Mac用)
#! /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