KDE plasma / Dolphin equivalent of a Nautilus script

Hey there!

I am so close to moving to Endeavour OS from my Ubuntu 22.04 install on my laptop. And thank you again to everyone who has helped me and answered my silly questions. I am trying to just double-check a few last things so that I do not lose too much productivity time after I make the switch.

Currently in my Ubuntu install I have 3 bash scripts I created that I use for quickly converting some file types that I use in my work on a regular basis. They are in my home folder under /home/ME/.local/share/nautilus/scripts

When I right click on a file, I have a menu item called Scripts and that expands to show my three bash scripts so I can run one against a given file. Is there something like this in KDE Plasma (or in Dolphin)? I love that I can create these scripts and drop them in the folder and they automatically show up in the right click menu. I tried Googling this and could not seem to find a clear (or understandable for me) answer.

If I can figure this out I will only have one or two things left to figure out and can then make the switch to Endeavour OS. I cannot remember what one of those things was, but I am hoping I will in the next few hours, lol. Not enough coffee yet today, but really is there any amount of coffee that is truly enough? I am so excited to be this close to making the switch and am hoping I can maybe do it Sunday evening or Monday morning. Thank you again for all of your help and putting up with my questions. This community is awesome and I am looking forward to becoming part of it. Hopefully one day I will know enough to be able to help others the way you have all helped me.

RevM

You add service menu entries to .local/share/kservices5/ServiceMenus

The desktop files look like this:

[Desktop Entry]
Type=Service
X-KDE-ServiceTypes=KonqPopupMenu/Plugin
MimeType=all/allfiles;
Actions=messageFun;
Encoding=UTF-8

[Desktop Action messageFun]
Name=Pointless message
Exec=kdialog --msgbox "This is pointless"

It will show up in the actions part of the context menu in dolphin.

2 Likes

Take a look at this link:

2 Likes

Okay, that helps a lot. So can I have the .desktop execute the bash script, or do I move the bash script into the .desktop file? For instance, this is one of the bash scripts I use:

#!/bin/bash
for fullpath in "$@"
do
    filename="${fullpath##*/}"                      # Strip longest match of */ from start
    dir="${fullpath:0:${#fullpath} - ${#filename}}" # Substring from 0 thru pos of filename
    base="${filename%.[^.]*}"                       # Strip shortest match of . plus at least one non-dot char from end
    ext="${filename:${#base} + 1}"                  # Substring from len of base thru end
    if [[ -z "$base" && -n "$ext" ]]; then          # If we have an extension and no base, it's really the base
        base=".$ext"
        ext=""
        #newdir=/"$base"/"$base"
    fi
    
    printf 'Creating directory\n' >> log
    mkdir $base || exit
    printf 'Converting PDF to PNGs\n' >> log
    printf "$filename /$base/$base\n" >> log
    pdftoppm -png "$filename" "./$base/$base"
    printf 'All done\n\n' >> log
    
done

I can confirm what dalto said.

I made my own

/home/user/.local/share/kservices5/ServiceMenus/7zip_wine.desktop

I copied from p7zip-gui . You can check the components after installation with “pacman -Qil p7zip-gui”.

[Desktop Entry]
Type=Service
ServiceTypes=all/allfiles
MimeType=all/all;
Actions=CompressDialog;test;hash;Compress7z;CompressZip;ExtractTo;
X-KDE-Priority=TopLevel
X-KDE-Submenu=7-Zip (wine)
#X-KDE-Icon=wine
X-KDE-ServiceTypes=KonqPopupMenu/Plugin

#X-Desktop-File-Install-Version=0.26

[Desktop Action CompressDialog]
Name=Add to Archive ...
#Icon=wine
Exec=wine "C:\\Program Files\\7-Zip\\7zG.exe" -ad a %n.7z %n

[Desktop Action test]
Name=Test Archive
Exec=wine "C:\\Program Files\\7-Zip\\7zG.exe" -ad t %U
#Icon=wine

[Desktop Action hash]
Name=Hash (all)
Exec=wine "C:\\Program Files\\7-Zip\\7zG.exe" -ad h -scrc* %U
#Icon=wine

[Desktop Action Compress7z]
Name=Add to 7z Archive
#Icon=p7zip
Exec=wine "C:\\Program Files\\7-Zip\\7zG.exe" a -t7z %n.7z %n

[Desktop Action CompressZip]
Name=Add to Zip Archive
#Icon=p7zip
Exec=wine "C:\\Program Files\\7-Zip\\7zG.exe" a -tzip %n.zip %n

[Desktop Action ExtractTo]
Name=Extract to ...
#Icon=p7zip
Exec=wine "C:\\Program Files\\7-Zip\\7zG.exe" -ad x %U

Update1 :
https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#exec-variables

1 Like

Definitely have the desktop execute the script file.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.