3

I created a .sh script for simple OCR-ing of screenshots that I make with Shutter. The script looks like this (ocrFile.sh):

#!/bin/bash

convert $1 /tmp/output.pnm
cat /tmp/output.pnm | pamstretch 4 > /tmp/stretched.pnm
convert /tmp/stretched.pnm -colorspace gray /tmp/output600dpi.tif
tesseract /tmp/output600dpi.tif ./outputText -l eng

This script does some image enhancing that is required when OCRing with tesseract. It does the job properly if it is called from the terminal. What I wanted was to do the whole process within Nemo, so I created a custom action named OCR.nemo_action inside /home/user1/.local/share/nemo/actions with the following content:

[Nemo Action]
Name=OCR The Screenshoot
Comment=OCR Function for Nemo File Manager
Exec=<ocrFile.sh %F>
Icon-Name=gtk-execute
Selection=Any
Extensions=png;

This Nemo action don't produce output with the script given above. The .sh script is also in the folder for Nemo's custom actions.

Please help!

2
  • It is impossible to debug, since typing 'nemo' in the terminal launches the application and returns the prompt. Feb 11, 2014 at 18:05
  • The whole process works under Mint Mate. The parameter for picking up the file was only %f instead of %F. Feb 11, 2014 at 19:19

3 Answers 3

1

Great!!

-- ~/OCR.sh ( chmod +x ~/OCR.sh )

#!/bin/bash
convert $1 /tmp/OCR-output.pnm
cat /tmp/OCR-output.pnm | pamstretch 4 > /tmp/OCR-stretched.pnm
convert /tmp/OCR-stretched.pnm -colorspace gray /tmp/OCR-output600dpi.tif 
tesseract /tmp/OCR-output600dpi.tif ~/Desktop/OCR-outputText -l eng 
rm /tmp/OCR-output.pnm /tmp/OCR-stretched.pnm /tmp/OCR-output600dpi.tif

-- ~/.local/share/nemo/actions

[Nemo Action]
Active=true
Name=OCR picture
Comment=OCR Function for Nemo File Manager
Selection=S
Exec=/bin/bash /home/user/OCR.sh %F                 --- change "user"
Icon-Name=gtk-execute
Extensions=png;jpg;jpeg;bmp;

And OCR text is on my Desktop !!!

1

I kind of came to solution for this situation in Cinnamon. The .nemo_action file consists of the following content.

[Nemo Action]
Name=OCR The Screenshoot
Comment=OCR Function for Nemo File Manager
Selection=S
Exec=gnome-terminal --working-directory=%P -e "/media/storage/Scripts/actions/ocrFile.sh %F"
Icon-Name=gtk-execute
Extensions=png;jpg;jpeg;bmp;
Active=true

Having terminal launch to do the job is rather a workaround here. Everything else didn't seem to yield results.

The bash script itself remained pretty much the same, altered only for a directive to keep the terminal open until the execution of the command set.

#!/bin/bash
convert $1 /tmp/output.pnm
cat /tmp/output.pnm | pamstretch 4 > /tmp/stretched.pnm
convert /tmp/stretched.pnm -colorspace gray /tmp/output600dpi.tif 
tesseract /tmp/output600dpi.tif ./outputText -l eng 
rm /tmp/output.pnm /tmp/stretched.pnm /tmp/output600dpi.tif
bash

What I crave ultimately is to make this process completely terminal-free. It seems to me that the process goes slightly differently from Gnome2 (Mate). Here the bash script which consists of terminal commands do not execute "somewhere in the background". With bash scripts that call GUI applications Gnome3's Exec= directive allows the <script.sh %F> value.

0
0

Is it a bash script? Try

Exec=/bin/bash /home/user1/.local/share/nemo/actionsocrFile.sh %F

(or even /bin/sh which is usually dash might be slightly faster.)

As for debugging, at the command line:

$ nemo -q # quit all instances of nemo
$ NEMO_ACTION_VERBOSE=1 nemo

Then run the action from the nemo window that will have opened up.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .