Add My Command to Service Menu

Well after all the generous help I got in the thread " OCR to Add Text to File"

I could make a little script to OCR a file and added it as a command.

Since then I was searching and reading to find a way to add this command which I called “ocr” to be in the service menu.

I think I found some app(s) to do it, but I think it is much simpler, maybe by editing a specific file and add the entry “OCR”.

How to?
I will highly appreciate your help.

But why?

Isn’t it easier to use it from a terminal?

It’s a command line utility, it takes filenames as arguments…

Well, I am just trying to make it a bit more “convenient” and honestly trying to learn something new.

Through command line:
1- you right click to open terminal
2- you type the command (maybe mistake in typing or qutation marks depending on filename.pdf or “file name.pdf”)
3- [EDIT] if the file is in a search result I would need to open the folder, find it again…!

In service menu you type nothing, you just right click and select “OCR”

As I said, I’m trying to make it easier and learn something new.

Well, I have been trying…
All what I can get for now is:
I have a “OCR.desktop” file in “/usr/share/kservices5/ServiceMenus/”

It is:

[Desktop Entry]

[Desktop Action Ocr]
Exec="/home/limo/MyScripts/" %F

Now all what I have is a sub menu entry “Ocr” where when I click it nothing happens to the file I right clicked!

Experienced user can help I hope.
The point is I am trying to make it more convenient to do something with a file.

P.S. I got some help at KDE forums but seems we are stuck!

I understand “EndeavourOS A terminal-centric distro with a vibrant and friendly community at its core” but any way it has desktops, uses mouse, clicks and right clicks anyway.

I will appreciate any inputs.

If you’re using Dolphin, read this:

1 Like

Now this makes sense to me. :laughing:

Edit: I can relate to this. :wink:

For example, if you have the KDE file archive utility Ark installed you will see a menu entry to “Extract here…” whenever you right-click on a file archive. The option to “Extract here…” is a servicemenu.

I am glad what what I am suggesting makes sense :rofl:


Yes, I am using Dolphin!
The link you provided says it is located at “kio/servicemenu” which I don’t have! Should I install kio?
For about 3 days now I have been reading and found some saying the “.desktop” file should be placed at "/usr/share/kservices5/ServiceMenus/” which I did.

My file as shown above. The problem is that nothing happens to the file when I right click!

I can guess the problem is in writing the “Exec=” command properly. I tried many things but couldn’t get it to work!

If you’ve done everything correctly, it should appear under Configure Dolphin → Context Menu:
Make sure you turn on the little checkbox.

WOW! :beers: :partying_face: :tada:
It now works

[Desktop Entry]

[Desktop Action Ocr]
## This Did Not Work ! WHY? Exec=/home/limo/MyScripts/ %F %F

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

I had to find where the command is, add %F %F (input and output files?!)

But I do not know why it is not working with my “.sh” script or with the Alias I created for my script “ocr”

It won’t work with aliases because aliases are loaded with .bashrc and that happens when you start the interactive shell session in the terminal (that is, when you launch your terminal emulator).

In this case, you have a non-interactive shell session which won’t load your .bashrc.

… and why it is not working with my “.sh” script?

Would it work if I made the “.sh” script in pyhton “.py”?

I don’t know why, it should work if you have #!/bin/bash as the first line of your script (or #!/usr/bin/env python3 for Python, on Arch, 3 is not necessary), and proper permissions set.

I checked Dolphin… it is already there and it is checked by itself.

OK… let me try this.
You are wonderful help @Kresimir
A wonderful community
A wonderful distro
:tada: :partying_face: :beers: :partying_face: :tada:

I made another file "OCR2.desktop

[Desktop Entry]

[Desktop Action Ocr2]
Exec=/home/limo/MyScripts/ %F %F

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

It did not work!

Not the .desktop file, the script!

Also run

chmod +x

to make it executable.

It is already there, and I could actually run it

echo $1
ocrmypdf -l ara+eng "$1" "$1"

I don’t know, you probably have a mistake somewhere.

Also, read this:


A command line may contain at most one %f, %u, %F or %U field code. If the application should not open any file the %f, %u, %F and %U field codes must be removed from the command line and ignored.