add create shortcut option to context menu

I followed the steps below to add the option to create a shortcut to the context menu:

  • I created a file named create_symlink.desktop in the ~/.local/share/kio/servicemenus directory and wrote the following in it:

[Desktop Entry]
Type=Service
X-KDE-ServiceTypes=KonqPopupMenu/Plugin
MimeType=inode/directory;application/octet-stream;
Actions=createSymlink;
Icon=insert-link

[Desktop Action createSymlink]
Name=Create Shortcut
Icon=insert-link
Exec=sh -c ‘for arg in “$@”; do ln -s “$arg” “${arg} - Shortcut”; done’ dummy %F

  • Then I ran the following code: chmod +x ~/.local/share/kio/servicemenus/create_symlink.desktop

  • With this option, when I right click on any file and click Create Shortcut, it creates a shortcut of that file in the same folder, but I have a problem.In Dolphin, when I right-click without selecting any file or folder, this “Create Shortcut” option appears again and when I click it, it creates an irrelevant shortcut to a parent folder. How do I make this “Create Shortcut” option appear only when I right click on a file or folder?

hi, welcome.

here is a primer on service menus in case you haven’t seen it yet.

if your question is how to control when the service menu appears in the context menu choices, that is all down to the MimeType… if it matches, the service menu appears.

here is a list of mime types you can use to distinguish between file types

1 Like

Well, your mimetype includes directory, hence the popup. Regardless if you set the priority to toplevel or not.
If I may add, you might wanna use a kdialog to have the link wherever you want it to be, maybe as a menu option.

Something along the lines of:

[Desktop Action 1LinkIt]
Name=Link It To..
Icon=edit-link
Exec=ln -s %F $(kdialog --getexistingdirectory)

I think what I want goes against the nature of the mimetype. Actually, this is not a very important issue, but I just asked because I was curious. I just want the “Make a Shortcut” option to appear if I select a file and right click on it, but it shows “Make a Shortcut” even if I click on an empty place.
I’ll try to make a video : streamable . com/6l57cp

You have direction as mimetype. Making it not appear on an “empty” space in a directory is not possible. Not that I’m aware of that is. So…grain of salt and all that.

As I said, it was not a very important thing anyway, but I wanted to ask because I was very curious.