Custom action in xfce4 Thunar: how to create a link under current directory? [closed]
Asked Answered
P

6

6

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.

Professionalize answered 9/1, 2014 at 15:24 Comment(0)
D
8

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.

Diaphaneity answered 24/7, 2015 at 12:57 Comment(0)
T
3

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

enter image description here

Tenstrike answered 11/2, 2014 at 6:31 Comment(2)
This only works for me if I add something to %n (because the filename of the link can't be the same as the target). For example, ln -s %f %n1 or ln -s %f %n-link. Or if you're like me and prefer relative links, ln -sr %f %n1.Maxfield
I found an even better solution. In my comment above, ln -sr %f %n1 changes text.txt to text.txt1. To change text.txt to text1.txt instead, use this command: ln -sr %f $(echo %n | sed -e 's/\(\.[a-zA-Z]*\)/1\1/g' )Maxfield
R
2
ln -s %f Link\ to\ %n

Works perfectly both for directories and files

Raddi answered 20/6, 2017 at 10:33 Comment(0)
A
1

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.

Alberic answered 19/7, 2018 at 5:33 Comment(0)
T
1
#!/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
Teno answered 15/10, 2019 at 18:39 Comment(0)
P
0

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.

Phox answered 16/8, 2021 at 19:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.