I have this line inside a Dolphin service-menu file that contains many other commands for PDF processing:

Exec=bash -c 'f="%u"; ocrmypdf "$f" "${f%.pdf}_ocr.pdf";'

It has the advantage of giving an output file of the form MY_PDF_ocr.pdf, thus keeping the name of the input file. But I would prefer to have the command running in terminal (konsole) so that I see the process.

For that, I can use the line:

Exec=konsole --noclose -e ocrmypdf "%u" ocr_en.pdf

but without the output keeping the name of the input.

A line like

Exec=konsole --noclose -e ocrmypdf "%u" "${%u}_ocr.pdf"

does nothing.

How to adjust the ocrmypdf so that the command is run in konsole and the output includes the name of the input?

1 Answer 1


After a few trials (and errors) a simple command like ocrmypdf %u %u_ocr.pdf will give an output file with an odd name (which includes the extension) of the formINPUT.pdf_ocr.pdf, and in the service menu:

Exec=konsole --noclose -e ocrmypdf %u %u_ocr.pdf

But a cleaner solution (inspired by what I could pick from here (on proper format of a script) and here (on using bash with a such script in terminal) seems to be to create a separate script (e.g. ocr_EN.sh) for that OCR-command - of the form (for English):

for f in "$@"
ocrmypdf "$f" "${f%.pdf}_ocr_EN.pdf"

Making it executable and then using the folowing command (here included in the line of a service menu file):

konsole --noclose -e bash /PATH/TO/ocr_EN.sh %f

which gives an output named INPUT_ocr_EN.pdf (without the extension appearing twice).

You must log in to answer this question.

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