Score:0

script that uses xclip not working from keyboard shortcut

cn flag

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?

guiverc avatar
cn flag
Are you sure that your system has fully-upgraded? as the 5.11 kernel should have been replaced by the 5.13 kernel within the last 48+ hours. Ensure your system is fully upgraded with all security fixes applied.
cn flag
yes it was updated to 5.13, then I noticed frequent crashes and downgraded to 5.11 after which the crashes have stopped. But I have solved my all question, thanks anyway
Score:1
cn flag

I was able to fix this by changing xclip and yomichan-search to the absolute paths to those scripts.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.