Command showing different behaviour when running from terminal and when Using as Shortcut

blueray

I am using KUbuntu 18.04.1

I am trying to extract text from screenshot using spectacle (Screenshot app of KUbuntu) & gocr (OCR tool)

If I give the commands one after another in Konsole (Terminal of KUbuntu)

First:

spectacle -r -b -n -o /home/UserName/Documents/Translate/input.jpg

Second:

gocr -i /home/UserName/Documents/Translate/input.jpg | xsel -b

It Works.

if I create a bash file screen_ts.sh and put the code

#!/bin/bash
# Dependencies: gocr xsel

# Take Screenshot and Save it to a File
spectacle -r -b -n -o /home/UserName/Documents/Translate/input.jpg

# Extract text from the saved file
gocr -i /home/UserName/Documents/Translate/input.jpg | xsel -b

exit

Open Konsole and type ./screen_ts.sh , it works

But, if I Make the file executable and double click, it take screenshot but does not save the text in clipboard.

Again if I create a custom shortcut using

Custom Shortcut > Trigger Alt + Q & Action /home/UserName/Documents/Translate/screen_ts.sh

KUbuntu Custom Shortcut

it take screenshot but does not save the text in clipboard. Same behavior as double click.

What is going on here?

danzel

From man xsel:

By default, this program outputs the selection without modification if both standard input and standard output are terminals (ttys). Otherwise, the current selection is output if standard output is not a terminal (tty), and the selection is set from standard input if standard input is not a terminal (tty). If any input or output options are given then the program behaves only in the requested mode.

This is a bit misleading, but there is an interesting comment in the source code:

Checking stdin/stdout for being a tty is NOT reliable to tell what the user wants. This is because child processes inherit the file descriptors of their parents; an xsel called in a script that is e.g. daemonized (not attached to a tty), or called with a redirection or in a pipeline will have non-tty file descriptors on default. The redirection/piping issue also applies to "grouped" or "compound" commands in the shell (functions, subshells, curly-brace blocks, conditionals, loops, etc.). In all these cases, the user must set the mode of operation explicitly.

...and that's the solution: tell xsel explicitly to read from stdin by adding the -i option:

gocr -i /home/UserName/Documents/Translate/input.jpg | xsel -b -i

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

grunt: command not found when running from terminal

From Java

Shortcut for running terminal command in VS code

From Dev

Why is hexdump of UTF-16 string when passed in as a command line argument different from what it is directly on the terminal?

From Dev

Different behaviour when using ELEMENTS XSINIL on SQL 2005 and SQL 2012

From Dev

Achieve different behaviour when accessing from other domain

From Dev

Unable to stop the Bash command running when terminal is opened

From Dev

QMake - Erratic behaviour When using echo System Command

From Dev

Why am I getting different behaviour when clicking Resharper "Run all tests" button vs using the keyboard shortcut command?

From Dev

Different app behaviour when deployed locally and from Store

From Dev

Why do some programs running from Terminal using '&' close when Terminal does and others do not?

From Dev

ModuleNotFoundError when running script from Terminal

From Dev

Command showing different behaviour when running from terminal and when Using as Shortcut

From Dev

Different behaviour when running exe from command prompt than in windows

From Dev

Why do some programs running from Terminal using '&' close when Terminal does and others do not?

From Dev

Why is hexdump of UTF-16 string when passed in as a command line argument different from what it is directly on the terminal?

From Dev

Different behaviour when using ELEMENTS XSINIL on SQL 2005 and SQL 2012

From Dev

SoapUI behaviour when teststep invoked from testcase is different

From Dev

Different DataFrame plotting behaviour when using FigureCanvasQTAgg

From Dev

Different behaviour when using a command line script or running it from a backgroundworker

From Dev

automatically disown application when running it from a terminal

From Dev

Different app behaviour when deployed locally and from Store

From Dev

"Command not found" error when running bash from anywhere but Cygwin desktop shortcut

From Dev

How to remove folder from showing when running the svn status command?

From Dev

Behaviour different when debugging

From Dev

Unexpected grep behaviour when using command substituiton

From Dev

File Manager showing different behaviour when opened as root and as a normal user

From Dev

(Windows Terminal) How to stop double printing of current working directory when running a command from a doskey macro file?

From Dev

Why does the terminal show different output when I'm connected as the same user running the same command?

From Dev

Konsole terminal showing tearing when running commands

Related Related

  1. 1

    grunt: command not found when running from terminal

  2. 2

    Shortcut for running terminal command in VS code

  3. 3

    Why is hexdump of UTF-16 string when passed in as a command line argument different from what it is directly on the terminal?

  4. 4

    Different behaviour when using ELEMENTS XSINIL on SQL 2005 and SQL 2012

  5. 5

    Achieve different behaviour when accessing from other domain

  6. 6

    Unable to stop the Bash command running when terminal is opened

  7. 7

    QMake - Erratic behaviour When using echo System Command

  8. 8

    Why am I getting different behaviour when clicking Resharper "Run all tests" button vs using the keyboard shortcut command?

  9. 9

    Different app behaviour when deployed locally and from Store

  10. 10

    Why do some programs running from Terminal using '&' close when Terminal does and others do not?

  11. 11

    ModuleNotFoundError when running script from Terminal

  12. 12

    Command showing different behaviour when running from terminal and when Using as Shortcut

  13. 13

    Different behaviour when running exe from command prompt than in windows

  14. 14

    Why do some programs running from Terminal using '&' close when Terminal does and others do not?

  15. 15

    Why is hexdump of UTF-16 string when passed in as a command line argument different from what it is directly on the terminal?

  16. 16

    Different behaviour when using ELEMENTS XSINIL on SQL 2005 and SQL 2012

  17. 17

    SoapUI behaviour when teststep invoked from testcase is different

  18. 18

    Different DataFrame plotting behaviour when using FigureCanvasQTAgg

  19. 19

    Different behaviour when using a command line script or running it from a backgroundworker

  20. 20

    automatically disown application when running it from a terminal

  21. 21

    Different app behaviour when deployed locally and from Store

  22. 22

    "Command not found" error when running bash from anywhere but Cygwin desktop shortcut

  23. 23

    How to remove folder from showing when running the svn status command?

  24. 24

    Behaviour different when debugging

  25. 25

    Unexpected grep behaviour when using command substituiton

  26. 26

    File Manager showing different behaviour when opened as root and as a normal user

  27. 27

    (Windows Terminal) How to stop double printing of current working directory when running a command from a doskey macro file?

  28. 28

    Why does the terminal show different output when I'm connected as the same user running the same command?

  29. 29

    Konsole terminal showing tearing when running commands

HotTag

Archive