Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make maimpick OCR to work with languages other than English. #1429

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

forgoty
Copy link

@forgoty forgoty commented Aug 3, 2024

If you work with human languages other than English this might be useful. List of available languages for OCR is selected from local tesseract configuration.

@emrakyz
Copy link
Contributor

emrakyz commented Aug 3, 2024

Your command is a little bit bloated. You don't need to use several processes. Especially try to never use awk, which is an extremely big and complex software for a simple task. awk is only necessary for extremely complex tasks (sometimes it makes things easier though).

You can do the same thing with a single sed command.

tesseract --list-langs 2>/dev/null | sed '1d;/^List/d;/osd/d'

On the other hand, tesseract can work with stdin and stdout. You don't need to create a temp image. You can remove ocr_cmd function completely.

maim -u -s | tesseract stdin stdout -l eng | xclip -sel clip

By the way your case statements lack readability. You should use a printf abstraction.

opts="a selected area
current window
full screen
a selected area (copy)
current window (copy)
full screen (copy)
copy selected image to text
copy selected image to text (choose language)"

opt="$(printf "%s\n" "${opts}" | dmenu -l 7 -i -p "Screenshot which area?")"

case "${opt}" in
        "a selected area") command ;;
        ...) command ;;
esac

@forgoty
Copy link
Author

forgoty commented Aug 3, 2024

@emrakyz thanks for useful comment. I've adjusted the script. Please take a look.

@emrakyz
Copy link
Contributor

emrakyz commented Aug 4, 2024

@forgoty

Looks good.

Keep that in mind, if you ever want to use the same option list in an indented way (inside functions), you can use cat <<- EOF. But this only works with tabs, not spaces.

Such as:

main() {
        C="$(
                cat <<- EOF | m "Torrents"
	List
	Add
	Remove
	Torrent Prio
	File Prio
	Start/Stop
	Disable All Files
	Search
	Killall
	EOF
        )"

        case "${C}" in
                "Add") add ;;
                "Remove") remove ;;
                "List") list ;;
                "Torrent Prio") tor_prio ;;
                "File Prio") file_prio ;;
                "Start/Stop") start_stop ;;
                "Disable All Files") no_download ;;
                "Search") search ;;
                "Killall") killsv ;;
                *) exit ;;
        esac
}

Or you can use something like this:

pr() { printf "%s\n" "${@}"; }

C="$(pr "List" \
        "Add" \
        "Remove" \
        "Torrent Prio" \
        "File Prio" \
        "Start/Stop" \
        "Disable All Files" \
        "Search" \
        "Killall" | m "Torrents")"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants