How to customize files context menu in Xubuntu XFCE Thunar file manager?
772
I generally prefer XFCE desktop environment of Xubuntu, but I found its files right-click context menu too humble (no option to compress/decompress files for example, and I'd like some my very special actions there too).
The best way to do this is to use the excellent Thunar custom actions feature (now installed as default with Thunar), and as there are no detailed tutorials here I thought it was worth adding one. When a custom action is created it is added to the context menu, as I will show in my discussion below. However, you can tailor when it appears in the context menu and, for example, make sure that your custom action only appears when image files are right-clicked on.
In thunar, if you go to edit > configure custom actions, you will see the menu as below (minus my custom actions of course):
You can either create a new custom action (see the discussion below) or edit an existing one. There are many useful examples at the Xfce site and at the Ubuntu wiki, so there is no need to go through them all here, but we will just discuss a few examples to display the usefulness of this feature in Thunar.
You would create a new custom action by clicking the add button (shown in the first screenshot). Then you would put the below command, for example, in the command box (like I have done for a different example in screenshot 2):
and then make sure that the correct file types were selected in the Appearance Conditions menu (as I have done for a different example in screenshot 3).
The command above uses srm (which is in the package called secure-delete), and one should be very careful in using it on files. Hence, the GNOME dialog program, Zenity, is often used if confirmation is needed for the actions (like it was used here) so that files are not removed accidentally.
However, to use a safer example than srm, we can use the example of espeak, so that we can get espeak to read any text file to us. We would create a new custom action and then we would put in the command box (as in screenshot 2)
espeak -s 135 -f %f
Espeak needs to be installed if it isn't already (with sudo apt-get install espeak); the -s option I have used just slows down the speed of the speech a bit; you can specify other parameters as well like different voices, but the -f switch must always go before %f as it shows espeak the text input file to use.
(You can add an icon if you wish (see the screenshot below), so that the context menu looks more interesting.)
Now, only when you right click a text file, will the espeak option come up, as in the screenshot below.
There is so much more that can be done with custom actions, but this was just an introduction to the basic ways of creating your own context menu item. There is a lot more information at the Xfce wiki and a lot of useful examples, and there are also some excellent examples of custom actions in this forum.
To restrict a command to a certain type of files:
only to txt: under 'Appearance conditions' tab, check 'Text files', and then add *.txt for 'File pattern'.
only for png: check 'Image files', and *.png for 'File pattern'.
only for flv: 'Video files', and *.flv.
for other files, like pdf: check 'Other files', and add *.pdf.
etc.
The main way to add new context menu options is (as Mik said) done by going to 'Edit/Configure custom actions' - and clicking "+" to add.
To add wine apps is more tricky. See this answer for Foobar2000 player comming also from Mik.
Although the script might not work for all apps, I have tried it on 7-zip archiver too and it works.
Didn't see this mentioned anywhere and this was one of the top search results related to adding Xfce custom actions, so...
If anyone wants to add entries to Thunar's right-click/context menu BUT wants to avoid the GUI for some reason, here is what worked for me. In my case, I wanted to do this as part of a post-install setup script that could be run on multiple computers.
It appears that adding things via the GUI mentioned in the other answers saves to the file ~/.config/Thunar/uca.xml. Under Fedora 35 Xfce / Thunar 4.16.10, this had a sample entry for "Open Terminal Here" by default.
Adding another <action>...</action> section with the appropriate details before the closing </actions> tag seemed to work as expected for me.
For example, I added:
<action>
<icon>org.gnome.Meld</icon>
<name>Compare selected</name>
<unique-id>1654579259785630-2</unique-id>
<command>meld %F</command>
<description>Compares selected files or folders in Meld</description>
<patterns>*</patterns>
<directories/>
<text-files/>
</action>
And was then able to see an option for doing Meld comparisons when I selected multiple files/folders. You might need to have the target app already installed for it to work (I already had meld installed).
Thunar picked the changes up right away for me after I closed open instances but if not, then you may need to kill/restart thunar (e.g. pkill -if thunar) or restart the pc for the changes to take effect.
I will likely just copy the file after I have it set up but if I decide to make a function wrapping xmlstarlet etc commands for this, then I'll try to remember to post a copy here as well.
The best way to do this is to use the excellent Thunar
custom actions
feature (now installed as default withThunar
), and as there are no detailed tutorials here I thought it was worth adding one. When a custom action is created it is added to the context menu, as I will show in my discussion below. However, you can tailor when it appears in the context menu and, for example, make sure that your custom action only appears when image files are right-clicked on.In
thunar
, if you go to edit > configure custom actions, you will see the menu as below (minus my custom actions of course):You can either create a new custom action (see the discussion below) or edit an existing one. There are many useful examples at the Xfce site and at the Ubuntu wiki, so there is no need to go through them all here, but we will just discuss a few examples to display the usefulness of this feature in
Thunar
.You would create a new custom action by clicking the add button (shown in the first screenshot). Then you would put the below command, for example, in the command box (like I have done for a different example in screenshot 2):
and then make sure that the correct file types were selected in the Appearance Conditions menu (as I have done for a different example in screenshot 3).
The command above uses
srm
(which is in the package calledsecure-delete
), and one should be very careful in using it on files. Hence, the GNOME dialog program,Zenity
, is often used if confirmation is needed for the actions (like it was used here) so that files are not removed accidentally.However, to use a safer example than
srm
, we can use the example ofespeak
, so that we can getespeak
to read any text file to us. We would create a new custom action and then we would put in the command box (as in screenshot 2)Espeak
needs to be installed if it isn't already (withsudo apt-get install espeak
); the-s
option I have used just slows down the speed of the speech a bit; you can specify other parameters as well like different voices, but the-f
switch must always go before%f
as it showsespeak
the text input file to use.(You can add an icon if you wish (see the screenshot below), so that the context menu looks more interesting.)
Now, only when you right click a text file, will the
espeak
option come up, as in the screenshot below.There is so much more that can be done with custom actions, but this was just an introduction to the basic ways of creating your own context menu item. There is a lot more information at the Xfce wiki and a lot of useful examples, and there are also some excellent examples of custom actions in this forum.
To restrict a command to a certain type of files:
txt
: under 'Appearance conditions' tab, check 'Text files', and then add*.txt
for 'File pattern'.png
: check 'Image files', and*.png
for 'File pattern'.flv
: 'Video files', and*.flv
.pdf
: check 'Other files', and add*.pdf
. etc.Look at these links,
Thunar plugins cover a limited area of options.
The main way to add new context menu options is (as Mik said) done by going to 'Edit/Configure custom actions' - and clicking "+" to add.
To add wine apps is more tricky. See this answer for Foobar2000 player comming also from Mik. Although the script might not work for all apps, I have tried it on 7-zip archiver too and it works.
Didn't see this mentioned anywhere and this was one of the top search results related to adding Xfce custom actions, so...
If anyone wants to add entries to Thunar's right-click/context menu BUT wants to avoid the GUI for some reason, here is what worked for me. In my case, I wanted to do this as part of a post-install setup script that could be run on multiple computers.
It appears that adding things via the GUI mentioned in the other answers saves to the file
~/.config/Thunar/uca.xml
. Under Fedora 35 Xfce / Thunar 4.16.10, this had a sample entry for "Open Terminal Here" by default.For me, this file contained (before modifying):
Adding another
<action>...</action>
section with the appropriate details before the closing</actions>
tag seemed to work as expected for me.For example, I added:
And was then able to see an option for doing Meld comparisons when I selected multiple files/folders. You might need to have the target app already installed for it to work (I already had meld installed).
Thunar picked the changes up right away for me after I closed open instances but if not, then you may need to kill/restart thunar (e.g.
pkill -if thunar
) or restart the pc for the changes to take effect.I will likely just copy the file after I have it set up but if I decide to make a function wrapping
xmlstarlet
etc commands for this, then I'll try to remember to post a copy here as well.