Custom action in xfce4 Thunar: how to create a link under current directory?

8.7k Views Asked by At

In Thunar, it is possible to define custom actions. There is already a "send to desktop (create link)" option in the right-click menu.

What I want is to add a self-defined action in Thunar that could create a link of a file or folder under current directory so that I can copy it to anywhere I want right away, instead of going to the Desktop at first by using the "send to" option already available.

How to do this?

I know I can do this in a terminal with the "ln" command, but I cannot figure out how to assign a new name for the created link in the context menu command.

6

There are 6 best solutions below

0
On
#!/bin/bash

# 'paste links' custom action for thunar
# + process multiple files
# + support non-ascii file names

# custom action settings
# + command like `~/bin/_paste_links %f`
# + appearance condition: directories

# require: xclip
# no license + no warranty

o="$1"
[ -z "$o" ] && o=./ # default target dir = $PWD
[ ! -d "$o" ] && exit 1

while read i; do

    if [[ "${i:0:1}" != '/' ]] \
    && [[ "${i:0:8}" = 'file:///' ]]
    then
        # decode path
        i="${i:7}" # remove 'file://' prefix
        i=$(echo -e "${i//%/\\x}") # urldecode
    fi

    [ ! -e "$i" ] && continue # file exists?

    # -r = create relative link
    ln -v -s -r "$i" "$o" # create link

done < <(xclip -o -se c; echo) # process substitution
0
On

You can use the thunar-plugins python package. It lets you choose via a file dialog how to name and where to put the new link for the selected file or directory.

It also installs a Checksums action and a Plugins manager for managings plugins that use it. Both you can disable if you desire.

2
On

Go to Edit - Configure custom actions and try the following custom action.

enter image description here

0
On

Thunar 1.6.3 Stand on folder/file you want to make link to (highlighted) Go to Edit (in main menu) and choose Make link.

0
On

With the help of this thread I've made a shell script to paste symlink from the path in the clipboard:

#! /bin/sh

XCLIP=`xclip -o -selection c`
if [ -f "$XCLIP" ] && [ -d "$1" ]; then
  ln -s "$XCLIP" "$1"
fi

and put a call to it into a custom actions (/full/path/pastel.sh %f). Needed to chose directories and 'any files' in the custom actions checkboxes. I'm not really sure how %f works in this case... but it works. So now I finally have a "paste link" command in xfce.

0
On
ln -s %f Link\ to\ %n

Works perfectly both for directories and files