# Add My Command to Service Menu

**URL:** <https://forum.endeavouros.com/t/add-my-command-to-service-menu/29497>\
**Category:** Newbie\
**Created:** [July 22, 2022, 12:12pm UTC](https://forum.endeavouros.com/t/add-my-command-to-service-menu/29497 "2022-07-22T12:12:16Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![limotux](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/limotux/32/35347_2.png) [@limotux](https://forum.endeavouros.com/u/limotux)\
**Post date:** [July 22, 2022, 12:12pm UTC](https://forum.endeavouros.com/t/add-my-command-to-service-menu/29497/1 "2022-07-22T12:12:16Z")

</div>

Well after all the generous help I got in the thread " [OCR to Add Text to File](https://forum.endeavouros.com/t/ocr-to-add-text-to-file/29439)"

I could make a little script to OCR a file and [added it as a command.](https://forum.endeavouros.com/t/ocr-to-add-text-to-file/29439/67)

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.

---

<div class="post-metadata">

**Author:** ![Kresimir](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/kresimir/32/73739_2.png) [@Kresimir](https://forum.endeavouros.com/u/Kresimir)\
**Post date:** [July 22, 2022, 12:20pm UTC](https://forum.endeavouros.com/t/add-my-command-to-service-menu/29497/2 "2022-07-22T12:20:01Z")

</div>

But why?

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

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

---

<div class="post-metadata">

**Author:** ![limotux](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/limotux/32/35347_2.png) [@limotux](https://forum.endeavouros.com/u/limotux)\
**Post date:** [July 22, 2022, 12:36pm UTC](https://forum.endeavouros.com/t/add-my-command-to-service-menu/29497/3 "2022-07-22T12:36:58Z")

</div>

> [@Kresimir](#):
>
> Isn’t it easier to use it from a terminal?

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.

---

<div class="post-metadata">

**Author:** ![limotux](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/limotux/32/35347_2.png) [@limotux](https://forum.endeavouros.com/u/limotux)\
**Post date:** [July 24, 2022, 3:48pm UTC](https://forum.endeavouros.com/t/add-my-command-to-service-menu/29497/4 "2022-07-24T15:48:20Z")

</div>

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:

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

[Desktop Action Ocr]
Name=Ocr
Icon=application-pdf
Exec="/home/limo/MyScripts/ocr.sh" %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](https://forum.kde.org/viewtopic.php?f=224&t=175550&p=456599#p456599) 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.

---

<div class="post-metadata">

**Author:** ![Kresimir](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/kresimir/32/73739_2.png) [@Kresimir](https://forum.endeavouros.com/u/Kresimir)\
**Post date:** [July 24, 2022, 7:16pm UTC](https://forum.endeavouros.com/t/add-my-command-to-service-menu/29497/5 "2022-07-24T19:16:57Z")

</div>

If you’re using Dolphin, read this:

> **[Creating Dolphin Service Menus](https://develop.kde.org/docs/extend/dolphin/service-menus/)**
>
> Learn how to create dolphin service menus

---

<div class="post-metadata">

**Author:** ![ricklinux](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/ricklinux/32/110798_2.png) [@ricklinux](https://forum.endeavouros.com/u/ricklinux)\
**Post date:** [July 25, 2022, 12:02am UTC](https://forum.endeavouros.com/t/add-my-command-to-service-menu/29497/6 "2022-07-25T00:02:42Z")

</div>

Now this makes sense to me. 😆

Edit: I can relate to this. 😉

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.

---

<div class="post-metadata">

**Author:** ![limotux](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/limotux/32/35347_2.png) [@limotux](https://forum.endeavouros.com/u/limotux)\
**Post date:** [July 25, 2022, 5:02am UTC](https://forum.endeavouros.com/t/add-my-command-to-service-menu/29497/7 "2022-07-25T05:02:06Z")

</div>

> [@ricklinux](#):
>
> Now this makes sense to me. 😆

I am glad what what I am suggesting makes sense 🤣

> [@ricklinux](#):
>
> Edit: I can relate to this. 😉

👍

---

<div class="post-metadata">

**Author:** ![limotux](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/limotux/32/35347_2.png) [@limotux](https://forum.endeavouros.com/u/limotux)\
**Post date:** [July 25, 2022, 5:09am UTC](https://forum.endeavouros.com/t/add-my-command-to-service-menu/29497/8 "2022-07-25T05:09:51Z")

</div>

> [@Kresimir](#):
>
> If you’re using Dolphin

Yes, I am using Dolphin!  
The link you provided says it is located at “[kio/servicemenu](https://develop.kde.org/docs/extend/dolphin/service-menus/#:~:text=found%20in%20the-,kio/servicemenus,-directory%20in%20the)” 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!

---

<div class="post-metadata">

**Author:** ![Kresimir](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/kresimir/32/73739_2.png) [@Kresimir](https://forum.endeavouros.com/u/Kresimir)\
**Post date:** [July 25, 2022, 5:28am UTC](https://forum.endeavouros.com/t/add-my-command-to-service-menu/29497/9 "2022-07-25T05:28:51Z")

</div>

If you’ve done everything correctly, it should appear under Configure Dolphin → Context Menu:  
 ![image](https://forum.endeavouros.com/uploads/default/original/3X/a/4/a40760cab2fb5ea390c77a874cdf2dd5e01d7eec.png)  
Make sure you turn on the little checkbox.

---

<div class="post-metadata">

**Author:** ![limotux](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/limotux/32/35347_2.png) [@limotux](https://forum.endeavouros.com/u/limotux)\
**Post date:** [July 25, 2022, 5:47am UTC](https://forum.endeavouros.com/t/add-my-command-to-service-menu/29497/10 "2022-07-25T05:47:42Z")

</div>

WOW! 🍻 🥳 🎉  
It now works

```auto
[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=/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”

---

<div class="post-metadata">

**Author:** ![Kresimir](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/kresimir/32/73739_2.png) [@Kresimir](https://forum.endeavouros.com/u/Kresimir)\
**Post date:** [July 25, 2022, 5:49am UTC](https://forum.endeavouros.com/t/add-my-command-to-service-menu/29497/11 "2022-07-25T05:49:54Z")

</div>

> [@limotux](#):
>
> 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`.

---

<div class="post-metadata">

**Author:** ![limotux](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/limotux/32/35347_2.png) [@limotux](https://forum.endeavouros.com/u/limotux)\
**Post date:** [July 25, 2022, 5:53am UTC](https://forum.endeavouros.com/t/add-my-command-to-service-menu/29497/12 "2022-07-25T05:53:12Z")

</div>

> [@Kresimir](#):
>
> It won’t work with aliases because aliases are loaded with `.bashrc`

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

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

---

<div class="post-metadata">

**Author:** ![Kresimir](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/kresimir/32/73739_2.png) [@Kresimir](https://forum.endeavouros.com/u/Kresimir)\
**Post date:** [July 25, 2022, 5:55am UTC](https://forum.endeavouros.com/t/add-my-command-to-service-menu/29497/13 "2022-07-25T05:55:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![limotux](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/limotux/32/35347_2.png) [@limotux](https://forum.endeavouros.com/u/limotux)\
**Post date:** [July 25, 2022, 5:55am UTC](https://forum.endeavouros.com/t/add-my-command-to-service-menu/29497/14 "2022-07-25T05:55:55Z")

</div>

> [@Kresimir](#):
>
> it should appear under Configure Dolphin → Context Menu:

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

---

<div class="post-metadata">

**Author:** ![limotux](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/limotux/32/35347_2.png) [@limotux](https://forum.endeavouros.com/u/limotux)\
**Post date:** [July 25, 2022, 5:57am UTC](https://forum.endeavouros.com/t/add-my-command-to-service-menu/29497/15 "2022-07-25T05:57:38Z")

</div>

> [@Kresimir](#):
>
> it should work if you have `#!/bin/bash` as the first line of your script

OK… let me try this.  
You are wonderful help @Kresimir  
A wonderful community  
A wonderful distro  
🎉 🥳 🍻 🥳 🎉

---

<div class="post-metadata">

**Author:** ![limotux](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/limotux/32/35347_2.png) [@limotux](https://forum.endeavouros.com/u/limotux)\
**Post date:** [July 25, 2022, 6:04am UTC](https://forum.endeavouros.com/t/add-my-command-to-service-menu/29497/16 "2022-07-25T06:04:04Z")

</div>

I made another file "OCR2.desktop

```auto
#!/bin/bash
[Desktop Entry]
Type=Service
ServiceTypes=KonqPopupMenu/Plugin
MimeType=application/pdf;
Actions=Ocr2
Icon=applications-pdf

[Desktop Action Ocr2]
Name=Ocr2
Icon=application-pdf
Termial=true
Exec=/home/limo/MyScripts/ocr.sh %F %F

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

```

It did not work!

---

<div class="post-metadata">

**Author:** ![Kresimir](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/kresimir/32/73739_2.png) [@Kresimir](https://forum.endeavouros.com/u/Kresimir)\
**Post date:** [July 25, 2022, 6:06am UTC](https://forum.endeavouros.com/t/add-my-command-to-service-menu/29497/17 "2022-07-25T06:06:39Z")

</div>

Not the `.desktop` file, the script!

---

<div class="post-metadata">

**Author:** ![manuel](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/manuel/32/396_2.png) [@manuel](https://forum.endeavouros.com/u/manuel)\
**Post date:** [July 25, 2022, 6:09am UTC](https://forum.endeavouros.com/t/add-my-command-to-service-menu/29497/18 "2022-07-25T06:09:03Z")

</div>

Also run

```auto
chmod +x ocr.sh

```

to make it executable.

---

<div class="post-metadata">

**Author:** ![limotux](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/limotux/32/35347_2.png) [@limotux](https://forum.endeavouros.com/u/limotux)\
**Post date:** [July 25, 2022, 6:10am UTC](https://forum.endeavouros.com/t/add-my-command-to-service-menu/29497/19 "2022-07-25T06:10:08Z")

</div>

> [@Kresimir](#):
>
> Not the `.desktop` file, the script!

It is already there, and I could actually run it

```auto
#!/bin/bash
echo $1
ocrmypdf -l ara+eng "$1" "$1"

```

---

<div class="post-metadata">

**Author:** ![Kresimir](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/kresimir/32/73739_2.png) [@Kresimir](https://forum.endeavouros.com/u/Kresimir)\
**Post date:** [July 25, 2022, 6:16am UTC](https://forum.endeavouros.com/t/add-my-command-to-service-menu/29497/20 "2022-07-25T06:16:41Z")

</div>

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

Also, read this:  
[https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s07.html](https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s07.html)

specifically:

> 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.

[Next page](https://forum.endeavouros.com/t/add-my-command-to-service-menu/29497.md?page=2)
