<story><title>TextSnatcher: Copy text from images, for the Linux Desktop</title><url>https://github.com/RajSolai/TextSnatcher</url></story><parent_chain><item><author>bpfrh</author><text>I use the same script as Dibby053, copied from stackoverflow but with some tweaks to work on kde,gnome and wayland as well as x11 and with some notifications on what state it is in.&lt;p&gt;I didn&amp;#x27;t test the x11&amp;#x2F;wayland check yet, but feel free to use it and report back.&lt;p&gt;&lt;pre&gt;&lt;code&gt;  #!&amp;#x2F;bin&amp;#x2F;bash 
  # Dependencies: tesseract-ocr imagemagick 
  # on gnome: gnome-screenshot 
  # on kde: spectacle
  # on x11: xsel
  # on wayland: wl-clipboard

  die(){
  notify-send &amp;quot;$1&amp;quot;
  exit 1
  }
  cleanup(){
  [[ -n $1 ]] &amp;amp;&amp;amp;  rm -rf &amp;quot;$1&amp;quot;
  }

  SCR_IMG=$(mktemp)  || die &amp;quot;failed to take screenshot&amp;quot;

  # shellcheck disable=SC2064
  trap &amp;quot;cleanup &amp;#x27;$SCR_IMG&amp;#x27;&amp;quot; EXIT

  notify-send &amp;quot;Select the area of the text&amp;quot; 
  if  which &amp;quot;spectacle&amp;quot; &amp;amp;&amp;gt; &amp;#x2F;dev&amp;#x2F;null
  then
    spectacle -r -o &amp;quot;$SCR_IMG.png&amp;quot; || die &amp;quot;failed to take screenshot&amp;quot;
  else
    gnome-screenshot -a -f &amp;quot;$SCR_IMG.png&amp;quot; || die &amp;quot;failed to take screenshot&amp;quot;
  fi

  # increase image quality with option -q from default 75 to 100
  mogrify -modulate 100,0 -resize 400% &amp;quot;$SCR_IMG.png&amp;quot;  || die &amp;quot;failed to convert image&amp;quot;
  #should increase detection rate

  tesseract &amp;quot;$SCR_IMG.png&amp;quot; &amp;quot;$SCR_IMG&amp;quot; &amp;amp;&amp;gt; &amp;#x2F;dev&amp;#x2F;null || die &amp;quot;failed to extract text&amp;quot;
  if [ &amp;quot;$XDG_SESSION_TYPE&amp;quot; == &amp;quot;wayland&amp;quot; ]
  then 
  wl-copy &amp;lt; &amp;quot;$SCR_IMG.txt&amp;quot; || die &amp;quot;failed to copy text to clipboard&amp;quot;
  else
  xsel -b -i  &amp;lt; &amp;quot;$SCR_IMG.txt&amp;quot; || die &amp;quot;failed to copy text to clipboard&amp;quot;
  fi
  notify-send &amp;quot;Text extracted&amp;quot;
  exit

&lt;/code&gt;&lt;/pre&gt;
edit:&lt;p&gt;Formatting</text></item></parent_chain><comment><author>guipsp</author><text>I slightly modified your script to:
1. Clean up properly
2. Run spectacle in BG mode, so the window does not pop up after screenshotting.&lt;p&gt;&lt;pre&gt;&lt;code&gt;  #!&amp;#x2F;bin&amp;#x2F;bash 
  # Dependencies: tesseract-ocr imagemagick 
  # on gnome: gnome-screenshot 
  # on kde: spectacle
  # on x11: xsel
  # on wayland: wl-clipboard
  
  die(){
    notify-send &amp;quot;$1&amp;quot;
    exit 1
  }
  cleanup(){
    [[ -n $1 ]] &amp;amp;&amp;amp; rm -r &amp;quot;$1&amp;quot;
  }
  
  SCR_IMG=$(mktemp -d) || die &amp;quot;failed to take screenshot&amp;quot;
  
  # shellcheck disable=SC2064
  trap &amp;quot;cleanup &amp;#x27;$SCR_IMG&amp;#x27;&amp;quot; EXIT
  
  #notify-send &amp;quot;Select the area of the text&amp;quot; 
  if  which &amp;quot;spectacle&amp;quot; &amp;amp;&amp;gt; &amp;#x2F;dev&amp;#x2F;null
  then
    spectacle -b -r -o &amp;quot;$SCR_IMG&amp;#x2F;scr.png&amp;quot; || die &amp;quot;failed to take screenshot&amp;quot;
  else
    gnome-screenshot -a -f &amp;quot;$SCR_IMG&amp;#x2F;scr.png&amp;quot; || die &amp;quot;failed to take screenshot&amp;quot;
  fi
  
  # increase image quality with option -q from default 75 to 100
  mogrify -modulate 100,0 -resize 400% &amp;quot;$SCR_IMG&amp;#x2F;scr.png&amp;quot;  || die &amp;quot;failed to convert image&amp;quot;
  #should increase detection rate
  
  tesseract &amp;quot;$SCR_IMG&amp;#x2F;scr.png&amp;quot; &amp;quot;$SCR_IMG&amp;#x2F;scr&amp;quot; &amp;amp;&amp;gt; &amp;#x2F;dev&amp;#x2F;null || die &amp;quot;failed to extract text&amp;quot;
  if [ &amp;quot;$XDG_SESSION_TYPE&amp;quot; == &amp;quot;wayland&amp;quot; ]
  then 
    wl-copy &amp;lt; &amp;quot;$SCR_IMG&amp;#x2F;scr.txt&amp;quot; || die &amp;quot;failed to copy text to clipboard&amp;quot;
  else
    xsel -b -i  &amp;lt; &amp;quot;$SCR_IMG&amp;#x2F;scr.txt&amp;quot; || die &amp;quot;failed to copy text to clipboard&amp;quot;
  fi
  notify-send &amp;quot;Text extracted&amp;quot;
  exit&lt;/code&gt;&lt;/pre&gt;</text></comment>
<story><title>TextSnatcher: Copy text from images, for the Linux Desktop</title><url>https://github.com/RajSolai/TextSnatcher</url></story><parent_chain><item><author>bpfrh</author><text>I use the same script as Dibby053, copied from stackoverflow but with some tweaks to work on kde,gnome and wayland as well as x11 and with some notifications on what state it is in.&lt;p&gt;I didn&amp;#x27;t test the x11&amp;#x2F;wayland check yet, but feel free to use it and report back.&lt;p&gt;&lt;pre&gt;&lt;code&gt;  #!&amp;#x2F;bin&amp;#x2F;bash 
  # Dependencies: tesseract-ocr imagemagick 
  # on gnome: gnome-screenshot 
  # on kde: spectacle
  # on x11: xsel
  # on wayland: wl-clipboard

  die(){
  notify-send &amp;quot;$1&amp;quot;
  exit 1
  }
  cleanup(){
  [[ -n $1 ]] &amp;amp;&amp;amp;  rm -rf &amp;quot;$1&amp;quot;
  }

  SCR_IMG=$(mktemp)  || die &amp;quot;failed to take screenshot&amp;quot;

  # shellcheck disable=SC2064
  trap &amp;quot;cleanup &amp;#x27;$SCR_IMG&amp;#x27;&amp;quot; EXIT

  notify-send &amp;quot;Select the area of the text&amp;quot; 
  if  which &amp;quot;spectacle&amp;quot; &amp;amp;&amp;gt; &amp;#x2F;dev&amp;#x2F;null
  then
    spectacle -r -o &amp;quot;$SCR_IMG.png&amp;quot; || die &amp;quot;failed to take screenshot&amp;quot;
  else
    gnome-screenshot -a -f &amp;quot;$SCR_IMG.png&amp;quot; || die &amp;quot;failed to take screenshot&amp;quot;
  fi

  # increase image quality with option -q from default 75 to 100
  mogrify -modulate 100,0 -resize 400% &amp;quot;$SCR_IMG.png&amp;quot;  || die &amp;quot;failed to convert image&amp;quot;
  #should increase detection rate

  tesseract &amp;quot;$SCR_IMG.png&amp;quot; &amp;quot;$SCR_IMG&amp;quot; &amp;amp;&amp;gt; &amp;#x2F;dev&amp;#x2F;null || die &amp;quot;failed to extract text&amp;quot;
  if [ &amp;quot;$XDG_SESSION_TYPE&amp;quot; == &amp;quot;wayland&amp;quot; ]
  then 
  wl-copy &amp;lt; &amp;quot;$SCR_IMG.txt&amp;quot; || die &amp;quot;failed to copy text to clipboard&amp;quot;
  else
  xsel -b -i  &amp;lt; &amp;quot;$SCR_IMG.txt&amp;quot; || die &amp;quot;failed to copy text to clipboard&amp;quot;
  fi
  notify-send &amp;quot;Text extracted&amp;quot;
  exit

&lt;/code&gt;&lt;/pre&gt;
edit:&lt;p&gt;Formatting</text></item></parent_chain><comment><author>tmerse</author><text>I also used the very same script until I stumbled upon this on hn [0].&lt;p&gt;&lt;pre&gt;&lt;code&gt;    #!&amp;#x2F;usr&amp;#x2F;bin&amp;#x2F;env bash
    langs=(eng ara fas chi_sim chi_tra deu ell fin heb hun jpn kor nld rus tur)
    lang=$(printf &amp;#x27;%s\n&amp;#x27; &amp;quot;${langs[@]}&amp;quot; | dmenu &amp;quot;$@&amp;quot;)
    maim -us | tesseract --dpi 145 -l eng+${lang} - - | xsel -bi

&lt;/code&gt;&lt;/pre&gt;
[0]: &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;news.ycombinator.com&amp;#x2F;item?id=33704483#33705272&quot;&gt;https:&amp;#x2F;&amp;#x2F;news.ycombinator.com&amp;#x2F;item?id=33704483#33705272&lt;/a&gt;</text></comment>