How to make a dolphin extension to create hard links?

Hey!

Various programs don’t follow symlink paths, so I need to create hardlinks.

Is there a way to manipulate the drag-and-drop dialog for files, and add an option “hard link” there, which does ln -S file linked-file ?

Btw, with this command you can convert symlinks to hardlinks in a directory

#!/bin/bash

find -type l -exec bash -c 'ln -f "$(readlink -m "$0")" "$0"' {} \;

Add a Hard link option when moving/copying files in Dolphin is an old (and yet opened…) bug.
For a very specific purpose (create hard links in a subdiredcory named “BestOf”) I made a service menu in ~/.local/share/kio/servicemenus:

cat ln-to-bestof.desktop  
[Desktop Entry] 
Type=Service 
MimeType=MimeType=image/png;image/jpeg; 
X-KDE-ServiceTypes=KonqPopupMenu/Plugin 
Actions=Ln2BestOf 

[Desktop Action Ln2BestOf] 
Name=Hard Link To BestOf 
Name[en_GB]=Hard Link To BestOf 
Name[fr]=Lier en dur dans BestOf 
Icon=emblem-link 
Exec=/bin/ln %F ./BestOf

The file must be executable.
Hope this helps, but I’m not sure it meets your needs. May be it is possible to extend it with a script to choose a target directory, for example.
How To Create Dolphin service menus

3 Likes

no that is just a regular context menu extension. I would use it with a broader “all files” mimetype, and to make it work it needs to show in the “drag and drop” menu

The drag n drop option is not that easy for the regular Joe to make. A service menu shouldn’t be too hard. Here’s an example with a kdialog . The likes of: ln -s %F $(kdialog --getexistingdirectory)

2 Likes

Thank you very much @dzon ! For me, kdialog solves this issue.

Btw, I made the technical description how to implement natively for the drop popup:
https://bugs.kde.org/show_bug.cgi?id=328709#c18

3 Likes