You are not logged in.

#1 2021-01-03 21:50:26

sleekmason
Member
From: Ozarks
Registered: 2018-05-22
Posts: 376
Website

Pcmanfm and Thunar custom right-click actions

These are custom right-click actions for Both the pcmanfm and Thunar File manager that may be useful to others.

The Thunar options are in a single code box at the end of this list.

All options for Thunar are controlled from ~/.config/Thunar/uca.xml and can be changed either in the file itself, or from the "Configure Custom Actions" in the Thunar menu.

For some of the actions here, you will need to be able to obtain root on the fly. 
This means setting the environment variable in a small script.
See here for one way to do this: https://forums.bunsenlabs.org/viewtopic … 23#p106523

All listed actions use the command "gksudo" from the above link for those actions that require root. Change as desired/necessary.

Some have name translations for languages other than English, some don't.
Feel free to update and I will add back in here.

In order to use these actions for Pcmanfm, you will need the folder:

$HOME/.local/share/file-manager/actions

This folder should be created if it does not already exist.

mkdir -p $HOME/.local/share/file-manager/actions

When making new files for the actions folder, the filename must end in .desktop, as in "terminal.desktop"
It really doesn't matter the name for the most part, as it will be identified by whatever is placed
in the "name" category inside the action file.
Meaning, You can name it terminal.desktop, but it will
show up in your file manager as "Open Terminal Here"


Current actions:

- Open Folder As Root
- Edit as root
- Catfish file search in existing directory
- Set image as wallpaper using feh
- Open in terminal
- Attach to Thunderbird Mail
- Folder Attributes (ls -g info in terminal window of chosen folder.)
- File Sizes (Requires small program ncdu.)



### Open Folder as root

[Desktop Entry]
Type=Action
Tooltip=Open Folder As Root
Name=Open Folder As Root
Profiles=profile-zero;
Icon=gtk-dialog-authentication

Exec=/usr/local/bin/gksudo /usr/bin/pcmanfm %u

[X-Action-Profile profile-zero]
MimeTypes=inode/directory;
Exec=/usr/local/bin/gksudo /usr/bin/pcmanfm %u
Name=Default profile


### Edit as Root
*Note - Currently set for mousepad

[Desktop Entry]
Type=Action
Name=Edit as root
Name[it]=Modifica come root
Name[es]=Editar como root
Name[de]=Oeffnen mit Root-Rechten
Name[pt]=Editar como root
Name[fr]=Modifier en tant que root
Name[nl]=Bewerken als root
Name[pl]=Edytuj jako root
Name[ru]=Редактировать как root
Name[cz]=Upravit jako root
Icon=dialog-password
Profiles=profile-zero;

[X-Action-Profile profile-zero]
MimeTypes=text/*;application/*;
Exec=gksudo mousepad %f
Name=Default profile


### Catfish in current directory
There is actually a built in action for catfish already, but not in the main windows,
only if right-clicking directly on a folder.

[Desktop Entry]
Type=Action
Name=Catfish File Search
Icon=catfish
Profiles=profile-zero;

[X-Action-Profile profile-zero]
MimeTypes=inode/directory;
Exec=catfish --hidden %f
Name=Default profile


### Set as Wallpaper
*Note that this uses feh.  Change to suit.

[Desktop Entry]
Type=Action
Name=Set as wallpaper
Icon=user-desktop
Profiles=profile-zero;

[X-Action-Profile profile-zero]
MimeTypes=image/*;
Exec=feh --bg-scale %f
Name=Default profile
SelectionCount==1


### Open Terminal Here

[Desktop Entry]
Type=Action
Tooltip=Open Terminal Here
Name=Open Terminal
Profiles=profile-one;
Icon=utilities-terminal

[X-Action-Profile profile-one]
MimeTypes=inode/directory;
Exec=exo-open --working-directory %f --launch TerminalEmulator
Name=Default profile


### Attach to Thunderbird
*Note - this requires a separate script to be placed in $path -/usr/local/bin is a good place.

[Desktop Entry]
Type=Action
Name=Attach to Thunderbird Mail
Icon=thunderbird

Profiles=profile-zero;
[X-Action-Profile profile-zero]
MimeTypes=text/*;audio/*;image/*;application/*;
Exec=thunderbird-action %U
Name=Default profile


### Script for Attach to Thunderbird Mail
*Note - named thunderbird-action - /usr/local/bin

#!/bin/bash
# call thunderbird with -compose option and attach files as selected in pcmanfm
# called by .desktop in /home/my_username/.local/share/file-manager/actions

args=("$@")

new_string = ""

for i in "${args[@]}"
do
    new_string="${new_string},"
    new_string="${new_string}$i"
done

new_string="${new_string/,file:/file:}"

thunderbird -compose "attachment='$new_string'"


### Folder Attributes

[Desktop Entry]
Type=Action
Name=Folder Attributes
Icon=accessories-text-editor
Profiles=profile-zero;

[X-Action-Profile profile-zero]
MimeTypes=inode/directory;
Exec=urxvt --hold -e ls -AghS --color %f
Name=Default profile

### File Sizes
*Note -  The action requires installing a small program ncdu.

sudo apt install ncdu
[Desktop Entry]
Type=Action
Name=File Sizes
Icon=gparted
Profiles=profile-zero;

[X-Action-Profile profile-zero]
MimeTypes=inode/directory;
Exec=urxvt -e ncdu -rr %f
Name=Default profile

### Thunar Actions in ~/.config/Thunar/uca.xml
* Note - These commands match the above for pcmanfm, and should be adjusted
as necessary. You will need the separate script above to attach items to Thunderbird.
Also, For the use of File Sizes, you will need to install a small program:

sudo apt install ncdu
<?xml encoding="UTF-8" version="1.0"?>
<actions>
<action>
	<icon>catfish</icon>
	<name>Find files</name>
	<unique-id>1608480111388528-1</unique-id>
	<command>catfish --hidden %f</command>
	<description>Search for files with Catfish</description>
	<patterns>*</patterns>
	<directories/>
</action>
<action>
	<icon>utilities-terminal</icon>
	<name>Open terminal here</name>
	<unique-id>1608480111388550-2</unique-id>
	<command>exo-open --working-directory %f --launch TerminalEmulator</command>
	<description></description>
	<patterns>*</patterns>
	<directories/>
</action>
<action>
	<icon>system-file-manager</icon>
	<name>Open as root</name>
	<unique-id>1608480111388565-3</unique-id>
	<command>gksudo thunar %f</command>
	<description>Open directory as root</description>
	<patterns>*</patterns>
	<directories/>
</action>
<action>
	<icon>accessories-text-editor</icon>
	<name>Edit as root</name>
	<unique-id>1608480111388580-4</unique-id>
	<command>gksudo mousepad %F</command>
	<description>Edit text files as root</description>
	<patterns>*</patterns>
	<other-files/>
	<text-files/>
</action>
<action>
	<icon>accessories-text-editor</icon>
	<name>Folder Attributes</name>
	<unique-id>1610133896270522-1</unique-id>
	<command>urxvt --hold -e ls -AghS --color %f</command>
	<description>Detailed list in terminal.</description>
	<patterns>*</patterns>
	<directories/>
</action>
<action>
	<icon>preferences-desktop-wallpaper</icon>
	<name>Set As Background</name>
	<unique-id>1610134373979054-1</unique-id>
	<command>feh --bg-scale %f</command>
	<description>Set the current image as wallpaper</description>
	<patterns>*</patterns>
	<image-files/>
</action>
<action>
	<icon>thunderbird</icon>
	<name>Attach to Thunderbird</name>
	<unique-id>1610135671429381-1</unique-id>
	<command>thunderbird-action %U</command>
	<description>Attach File to Thunderbird</description>
	<patterns>*</patterns>
	<audio-files/>
	<image-files/>
	<other-files/>
	<text-files/>
</action>
<action>
	<icon>gparted</icon>
	<name>File Sizes</name>
	<unique-id>1610405390468673-1</unique-id>
	<command>urxvt -e ncdu -rr %F</command>
	<description>Lists Folder File Sizes</description>
	<patterns>*</patterns>
	<directories/>
</action>
</actions>

Remember to make the script executable.

I will gladly update the OP with any additions others might have.  If there is something
in particular I have left out that you would like to see, feel free to ask.

There are other actions to be found on github and the like, but not all of them are really useful anymore.

Last edited by sleekmason (2021-01-15 21:17:39)

Offline

#2 2021-01-04 09:45:11

ohnonot
...again
Registered: 2015-09-29
Posts: 5,197
Website

Re: Pcmanfm and Thunar custom right-click actions

Subscribed!


Please use CODE tags for code.
Search youtube without a browser: repo | thread
BL quote proposals to this thread please.
my repos / my repos

Offline

#3 2021-01-04 16:18:42

DeepDayze
Like sands through an hourglass...
From: In Linux Land
Registered: 2017-05-28
Posts: 1,074

Re: Pcmanfm and Thunar custom right-click actions

Nice but isn't gksu/gksudo now deprecated and what can replace these in custom actions requiring root access? Thunar's custom actions are similar but with different syntax of course.

Last edited by DeepDayze (2021-01-04 16:19:38)


Real Men Use Linux

Offline

#4 2021-01-04 20:00:26

sleekmason
Member
From: Ozarks
Registered: 2018-05-22
Posts: 376
Website

Re: Pcmanfm and Thunar custom right-click actions

DeepDayze wrote:

Nice but isn't gksu/gksudo now deprecated and what can replace these in custom actions requiring root access? Thunar's custom actions are similar but with different syntax of course.

Howdy, and, yes:)

All the script does is create a link to pkexec with the environment variable already in place. Basically, the script creates a one word shortcut to call for a root instance for whatever action/program you are using. This works great for calling programs in menus that require root access.

You can name the script whatever you want. Make sure to remember to change the name in the actions though.

I'm using gksudo out of prior familiarity and it's easy to remember:)  Seems like they would allow for just sudo to work for things like this but I suppose that might not be quite so good. lol.

Here is another, longer script that does the same thing:

#!/bin/bash
if [ -z $1 ]; then
 echo -e "at least 1 argument required!\n" >> /dev/stderr
 exit 1
fi
COMMAND=$1
shift #shift first arg
for ARG in "$@"
do
 if [ -z "$ARGS" ]; then
  ARGS="$ARG"
 else
  ARGS="$ARGS $ARG"
 fi 
done
ARGS=\'$ARGS\'
eval pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY $COMMAND $ARGS
exit 0

I called this one with xsudo, and used them both for a while:) No issues with either.

Offline

#5 2021-01-04 20:47:47

DeepDayze
Like sands through an hourglass...
From: In Linux Land
Registered: 2017-05-28
Posts: 1,074

Re: Pcmanfm and Thunar custom right-click actions

Cool, will try out that script for a custom action requiring root. Thanks for that. Xsudo sounds like a good name for it as no risk of clashing with anything :-)

OK created file with the content and called it gksudo and placed it in my $HOME/bin folder. Tested it with the actions and was able to run the edit as root action successfully. Nice little replacement for gksudo in being a mere wrapper for pkexec.

Last edited by DeepDayze (2021-01-05 04:17:30)


Real Men Use Linux

Offline

#6 2021-01-04 21:33:50

sleekmason
Member
From: Ozarks
Registered: 2018-05-22
Posts: 376
Website

Re: Pcmanfm and Thunar custom right-click actions

I would like to use ls -g in an action as well if anybody could change the exec line to what will actually work to open urxvt in the current folder with the info? 

Sneaky suspicion it has to be scripted.  Hoping not:)  If scripted, I suppose we could lose some of the redundant info.

- Or any suitable replacement to provide the same info on the fly?

*Edit SOLVED with:

Exec=urxvt --hold -e ls -g %f
[Desktop Entry]
Type=Action
Name=Folder Attributes
Icon=accessories-text-editor
Profiles=profile-zero;

[X-Action-Profile profile-zero]
MimeTypes=inode/directory;
Exec=urxvt -e "ls -g" %f
Name=Default profile

Last edited by sleekmason (2021-01-05 14:16:22)

Offline

#7 2021-01-05 07:26:22

ohnonot
...again
Registered: 2015-09-29
Posts: 5,197
Website

Re: Pcmanfm and Thunar custom right-click actions

DeepDayze wrote:

Nice but isn't gksu/gksudo now deprecated and what can replace these in custom actions requiring root access?

It is.
I use an almost identical action.
It uses

sudo -A pcmanfm %f

sudo -A uses the askpass helper defined in /etc/sudo.conf.
I defined

Path askpass /usr/local/sbin/zenityaskpass

/usr/local/sbin/zenityaskpass contains:

#!/bin/sh
exe=/usr/bin/zenity
[ -x "$exe" ] && exec $exe --password --title=sudo

I think yad could also be used for this, or the stark x11-ssh-askpass, or gnome-shh-askpass.
Then there's also /usr/lib/git-core/git-gui--askpass which belongs to git.


Please use CODE tags for code.
Search youtube without a browser: repo | thread
BL quote proposals to this thread please.
my repos / my repos

Offline

#8 2021-01-05 14:13:58

sleekmason
Member
From: Ozarks
Registered: 2018-05-22
Posts: 376
Website

Re: Pcmanfm and Thunar custom right-click actions

Added Folder attributes.  Opens urxvt with "ls -g" output for the chosen folder.

Offline

#9 2021-01-08 21:12:20

sleekmason
Member
From: Ozarks
Registered: 2018-05-22
Posts: 376
Website

Re: Pcmanfm and Thunar custom right-click actions

Added The configurations for Thunar as well.  The uca.xml is at the end of the list, and adds:

Set Background Here -this uses feh to set the wallpaper.
Attach To Thunderbird - Make sure to grab the script.
Folder Attributes - Opens urxvt with folder info.

Seems like my original config came from Bunsenlabs, but don't remember all that was on it. So, . .

Two Things:

1. If somebody wants to "Bunsenify" the Thunar code, I will replace/add? to the above to make it easy for folks to grab and use. Probably just change root command and programs if necessary. (mousepad, urxvt)

2. There is already a "Set Wallpaper" Located in the menu for Thunar, but won't work out of the box for me. (Using feh).
Do i need to set feh as default somewhere? galternatives doesn't give a hint. (<-Saying this now in the hopes that karma proves me wrong:)
Or, get rid of the old one? or, Change the command somewhere in Thunar?

Offline

#10 2021-01-09 02:41:03

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 7,556
Website

Re: Pcmanfm and Thunar custom right-click actions

sleekmason wrote:

There is already a "Set Wallpaper" Located in the menu for Thunar, but won't work out of the box for me. (Using feh).
Do i need to set feh as default somewhere? galternatives doesn't give a hint. (<-Saying this now in the hopes that karma proves me wrong:)
Or, get rid of the old one? or, Change the command somewhere in Thunar?

That's something default Thunar adds by itself, but requires xfdesktop4 (which you probably don't want to install).
BL's bunsen-thunar package does a dpkg-divert on /usr/lib/[x86_64-linux-gnu]/thunarx-3/thunar-wallpaper-plugin.so
(x86_64-linux-gnu will be different on systems with other architectures)

You could either install bunsen-thunar or just rename thunar-wallpaper-plugin.so manually to disable the disfunctional "Set Wallpaper" context menu item.


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#11 2021-01-09 03:45:23

sleekmason
Member
From: Ozarks
Registered: 2018-05-22
Posts: 376
Website

Re: Pcmanfm and Thunar custom right-click actions

johnraff wrote:

That's something default Thunar adds by itself, but requires xfdesktop4 (which you probably don't want to install).
BL's bunsen-thunar package does a dpkg-divert on /usr/lib/[x86_64-linux-gnu]/thunarx-3/thunar-wallpaper-plugin.so
(x86_64-linux-gnu will be different on systems with other architectures)

You could either install bunsen-thunar or just rename thunar-wallpaper-plugin.so manually to disable the disfunctional "Set Wallpaper" context menu item.

Certainly a solution then.  Good. Thank you for your response and links.  The diverter script is really cool.  I see what you are saying about using BL's Thunar:)

I may try to do a Thunar build?. I need to learn how to do this anyway.  I also need to set up a repository for oddball items at some point.  Looks like a good place to start if I can figure it all out.

Offline

#12 2021-01-09 06:35:30

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 7,556
Website

Re: Pcmanfm and Thunar custom right-click actions

^We don't ship a patched Thunar in fact. bunsen-thunar is a separate package that, when installed, disables the wallpaper right-click for thunar. Thunar itself has to be installed too, but the install order doesn't matter. Even without Thunar, bunsen-thunar's dpkg-divert will sit there waiting...

Uninstall b-t and t's wallpaper item will reappear.

Last edited by johnraff (2021-01-09 06:37:48)


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#13 2021-01-09 13:14:01

sleekmason
Member
From: Ozarks
Registered: 2018-05-22
Posts: 376
Website

Re: Pcmanfm and Thunar custom right-click actions

johnraff wrote:

^We don't ship a patched Thunar in fact. bunsen-thunar is a separate package that, when installed, disables the wallpaper right-click for thunar. Thunar itself has to be installed too, but the install order doesn't matter. Even without Thunar, bunsen-thunar's dpkg-divert will sit there waiting...

Uninstall b-t and t's wallpaper item will reappear.

Ah! okay, got it:) That's even better.  Sounds like the Bunsen package is the way to go in the end. Maybe today's Covid project. Good stuff.

Offline

#14 2021-01-11 23:10:03

sleekmason
Member
From: Ozarks
Registered: 2018-05-22
Posts: 376
Website

Re: Pcmanfm and Thunar custom right-click actions

Another action you may find useful.

File Sizes.  Retrieves the sizes of all files in a folder (recursive), with some navigation possible.

This action requires the installation of a small program to retrieve the info in an easy to read format.

sudo apt install ncdu
For pcmanfm:
[Desktop Entry]
Type=Action
Name=File Sizes
Icon=gparted
Profiles=profile-zero;

[X-Action-Profile profile-zero]
MimeTypes=inode/directory;
Exec=urxvt -e ncdu -rr %f
Name=Default profile


And for Thunar:

<action>
	<icon>gparted</icon>
	<name>File Sizes</name>
	<unique-id>1610405390468673-1</unique-id>
	<command>urxvt -e ncdu -rr %F</command>
	<description>Lists Folder File Sizes</description>
	<patterns>*</patterns>
	<directories/>
</action>

Offline

Board footer

Powered by FluxBB