Skip to content

Instantly share code, notes, and snippets.

@Amooti73
Last active March 8, 2022 07:06
Show Gist options
  • Save Amooti73/94dc1efe2fd120d6735cf0a3b21e2994 to your computer and use it in GitHub Desktop.
Save Amooti73/94dc1efe2fd120d6735cf0a3b21e2994 to your computer and use it in GitHub Desktop.
Click and drag to select a word or words on the screen and send them to rofi and then display the introductory section of the matching wikipedia article.
#!/bin/bash
# Dependencies: tesseract-ocr imagemagick scrot xsel wikit rofi
set -e
SCR_IMG=$(mktemp)
trap 'rm $SCR_IMG*' EXIT
scrot -s "$SCR_IMG.png"
mogrify -modulate 100,0 -resize 400% "$SCR_IMG.png" #should increase detection rate
tesseract "$SCR_IMG.png" "$SCR_IMG" &> /dev/null
cat "$SCR_IMG.txt" > wordy.txt
tr -d '\014' <wordy.txt > words.txt
src=$(cat words.txt)
test "$src" = "$(cat words.txt)"
rofi="rofi -dmenu -yoffset 30 -location 2"
pag() { \
eval "$rofi" -l 20 -p 'Done'
}
phrase=$(echo "$src"|eval "$rofi -markup -p 'Lookup '")
{
wikit "$phrase" --line 80 --link
} | pag
@Amooti73
Copy link
Author

This depends on wikit which must be installed with npm. It makes of this script which was posted on AskUbuntu.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment