Output of uname -a
: Linux negosaki 5.11.0-46-lowlatency #51~20.04.1-Ubuntu SMP PREEMPT Fri Jan 7 08:04:34 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
I have the following script in ~/bin/flameshot-ocr
, which is in my path:
#!/usr/bin/env bash
function ocr() {
filename=$1
lang=$2
outfile="/tmp/tesseract-output"
tesseract "$1" $outfile -l "$2"
cat "$outfile".txt
}
save_path="/tmp/flameshot-screenshot.png"
lang=$1
flameshot gui -r > "$save_path"
output=$(ocr "$save_path" "$lang")
echo "$output"
echo "$output" | xclip -selection clipboard
yomichan-search
exit 0
The yomichan-search
command is just another command I have in my path which uses xdotool
to bring a program I use to focus.
Basically, the script uses flameshot
to prompt me for a cropped screenshot, then saves that screenshot to /tmp/flameshot-screenshot.png
, and then uses tesseract with the provided language option to perform ocr on the image, and saves the result in /tmp/tesseract-output.txt
. Then, I use xclip to copy this output to my system clipboard. This all works when I run the script from my terminal, e.g. flameshot-ocr jpn_vert
. However, when I run it with a keyboard shortcut (the command flameshot-ocr jpn_vert
, only part of the script runs: I get prompted for a screenshot, the screenshot gets saved, tesseract is run on it, but the output does not get copied to my clipboard (xclip fails), and my yomichan-search
script doesn't run.
For reference, here is my yomichan-search
script:
#!/usr/bin/env bash
if [[ $(xdotool search yomichan) ]]; then
xdotool search yomichan windowactivate
else
/opt/google/chrome/google-chrome --profile-directory=Default --app-id=dmlhnpobnomcmidkoijomppdlpfkedmi
fi
I have verified that a simple command like echo "hello | xclip -selection clipboard"
works when I run it from my terminal, but not from a keyboard shortcut, and I have tried
sh -c 'echo "hello" | xclip -selection clipboard'
in the keyboard shortcut, which does work, but a keyboard shortcut like sh -c 'flameshot-ocr jpn_vert'
just does the exact same thing as when I didn't wrap it in sh -c
.
Does anyone know how to fix this?