Add My Command to Service Menu

With the script, not with the ocrmypdf command. :man_facepalming:

Of course it won’t work with the ocrympdf, since it expects two arguments (but in a desktop file you shouldn’t be passing the same string twice – it’s a mere accident that it works in your case).

I can understand
an algorithm that estimates 1/SQR(x)

The rest is too complicated for me… or precisely… I don’t have much patience!

I think after struggling with it for 3 days I deserve to have some good luck!

With that attitude, you’re always going to have unexplained bugs. That’s one of the reasons you’re struggling so much. Have you read the specifications for the Exec key in .desktop files I linked above?

I read it… may be I misunderstood something… but I will read again and take in consideration your comments.
I will just take a break as I have a few other tasks to do!

I will try - a bit later - and let you know.

I am not sure I follow.
The OCR.desktop file has the command “ocrmypdf” not my script “ocr.sh”
So, I am not using any scripts, I am using the command “ocrmydf”

Exec=konsole -e /home/limo/.local/bin/ocrmypdf -l ara+eng %F %F

Do you mean I should use only one %F instead of two in “Exec=”?

Not two %F but a single %f (there is a difference between uppercase and lowercase f), and you should be running a shell script which contains this command (because a single %f will not work with ocrmypdf).

Again, read the specification I linked to, everything is nicely explained therein.

Also, you shouldn’t be invoking konsole directly. Instead, if you want the terminal to open when your script is running (which is useful for scripts that require user input or have to show progress), you should add:

Terminal=true

to the .desktop file. You got bad advice from the KDE forum (which is to be expected).

I tried a single %f and a single %F in the file OCR.desktop
Both did not work!
It worked only with TWO %F despite I read again at the link you gave me that
Quote:
A command line may contain at most one %f, %u, %F or %U field code
UNQUOTE
Yes they say at most one %

To me this is a paradox! Two %F works while one %F does not! This is what actually happens in real time.

The only explanation is that the command requires two inputs.
Maybe at the link they were talking about commands that require only one input!

Am I missing something?!

UPDATE:
On web site another thing I noticed. In second line
“If no full path is provided the executable is looked up in the $PATH environment variable used by the desktop environment.”

I could run from the prompt ocrmypdf as usual and it runs normaly.
But when I put it in my .desktop file in the “Exec=” without specifying the path it did not work. I had to specify the path for it to work! Contrary to what is mentioned!

Yes.

First of all, forget about %F, it’s not for this purpose. Use %f. The difference should be clear to you from reading the specification.

You can’t run

/home/limo/.local/bin/ocrmypdf -l ara+eng

with a single file argument, it requires two. So it won’t work with a single %f, obviously.

But, according to the specification, you mustn’t put two %f into the Exec key:

Exactly. Not two.

So, how to solve this problem? Write a script that takes only one file argument as input, and passes it twice to the /home/limo/.local/bin/ocrmypdf and run that script with a single %f in the Exec key of the .desktop file.

Something like this:

#!/bin/bash
/home/limo/.local/bin/ocrmypdf -l ara+eng "$1" "$1"

Save it (for example as /home/limo/.local/bin/myocrscript.sh), make it executable (with sudo chmod u+x /home/limo/.local/bin/myocrscript.sh) and add its full filename (with path) to the Exec key with a single %f after it:

Exec=/home/limo/.local/bin/myocrscript.sh %f

It is OK with me. Don’t worry. I will take a break… rest… read again your comments and the link. Maybe I got confused with the script, the command, the .desktop file… I will take a break, a cup of coffee and get fresh.

Thank you for all your help and guidance.

Yeah, I think your mistake in the script above was lacking the full path to ocrmypdf. As I told you in that other thread, .bashrc is sourced only in the interactive shell session, which is not the case when running a script from a .destkop file.

Just copy and paste what I wrote, it should work.

And I have to admit -again- I am not that techie, so this might be the problem with me for misunderstanding.

So, please accept my apologies for my ignorance and accept my appreciation for your support and guidance.

Every shell script runs in a shell session. Interactive means that the user interacts with the shell. Interactive shell session is the one you run in the terminal (a terminal emulator is a program that runs interactive shell sessions, like Konsole).

At the start of every interactive Bash session, .bashrc is sourced and executed.

It is not sourced in non-interactive Bash sessions. So when you run a shell script from a .desktop file, your aliases won’t work and your PATH environment variable is not updated with this new path to the ocrmypdf program, because it’s a non-interactive shell session

I see there is a lot for me to learn!

Hopefully, that means you’ll live for a long time :rofl:

:joy::joy::joy::joy::joy:
Oh… I hope not! I hope I have learned a bit… enough to count my days​:joy:
I read a lot (economics mainly), I see

This WORKED perfectly :tada: :partying_face: :beers: :partying_face: :tada: :partying_face: :beers:
Now I understand how can I run my script.
Here is the file

[Desktop Entry]
Type=Service
ServiceTypes=KonqPopupMenu/Plugin
MimeType=application/pdf;
Actions=Ocr
Icon=applications-pdf

[Desktop Action Ocr]
Name=Ocr
Icon=application-pdf
Termial=true
## This Did Not Work ! WHY? Exec=/home/limo/MyScripts/ocr.sh %F %F
Exec=konsole -e /home/limo/.local/bin/ocr.sh %f
## This worked before Exec=konsole -e /home/limo/.local/bin/ocrmypdf -l ara+eng %F %F

And here is the script in “/home/limo/.local/bin/”

#!/bin/bash
echo $1
/home/limo/.local/bin/ocrmypdf -l ara+eng "$1" "$1"

This is the final word!
UPDATE:
Now I will take a break and another coffee
@Kresimir gave me hard time and didn’t let have a break till I finish this. He retaliated to the hard time I gave him!:rofl::rofl::rofl:
I am enjoying Endeavour University​:+1:

This is a joke, lest someone mistakes it for an accusation against my character of disturbing a fellow’s rest. In our private correspondence I had clearly stated that there is no hurry and to only mark the solution when its effectiveness has been proven through testing.

Of course I am joking.

Yes you did! It was me who felt committed to do it as soon as possible. Just to return the favour you gave me by being there and being so patient with me.

I was just joking of course.