Thunar is the file manager included in Xfce, a free and open source Desktop Environment which implements the traditional desktop metaphor, and has become the favorite of many users which switched to it when the GNOME project introduced the GNOME shell. Thunar is light on resources but doesn’t lack functionalities which can be extended further by creating custom actions.
In this tutorial we learn how to extend the Thunar file manager by creating custom actions.
In this tutorial you will learn:
- How to create custom actions from the Thunar interface
- How to create Thunar custom actions with a text editor
|Category||Requirements, Conventions or Software Version Used|
|Conventions||# – requires given linux-commands to be executed with root privileges either directly as a root user or by use of
Creating Thunar custom actions graphically
Although light on system resources, Thunar is a very handy file manager, which allows the user to create custom actions directly from its graphical interface. To create a custom action, what we need to do, is to navigate in the Thunar main menu and click on the “Edit -> Configure custom actions…” entry. This way we will access the dedicated graphical tool:
The custom action graphical tool allows the user to easily create, update and delete custom actions. As you can see in the above screenshot a custom action already exists (it is created by default): its purpose is to open the terminal emulator in a selected directory, by clicking on the related entry in the file manager context menu. To create a new custom action, we need to click on the “plus” icon:
The new window that will appear is composed by two tabs: “Basic” and “Appearance Conditions”. In the former, we can enter basic information for our custom action, in order:
- The action name: this is what will appear in the Thunar context menu
- The action description: this is a brief description of the purpose of the custom action
- The command invoked when the user clicks on the custom action entry in the Thunar context menu
- An optional keyboard shortcut for the custom action
- A checkbox to enable/disable startup notifications for our custom action
- An optional icon which will be displayed beside the action name in the Thunar context menu
In the “Appearance Conditions” tab, instead, we can establish the conditions which must be satisfied in order for the entry to appear in the Thunar context menu:
In the “File Pattern” field we can specify a single or a semicolon-separated list of file patterns which should be matched for the actions entry to appear in the menu. Here a “*” (glob) matches everything, so for example, if we want our action to appear only when files with the “.txt” extension are selected, we would write:
*.txt. Notice that this doesn’t discriminate on the base of the file type, but merely on its name.
To establish a rule based on file MIME types, instead, we must tick the appropriate checkboxes below this field. For our action entry to appear in the menu only when a text file is selected, for example, we would tick the “Text Files” checkbox. Notice that the action will be available only when the selection contains exclusively the specified type of files (in this case, for example, it won’t appear in the menu if we select a text file and an image file).
A trivial example
Let’s create a custom action as a trivial example. Our action will let us edit a selected image by opening it with GIMP, the GNU Image Manipulation Program. Here is how we populate the fields we saw above:
As you can see, we choose “Edit with Gimp” as the name of our custom action, provided a brief description for it, and entered
gimp %f as the command that will be executed when the user clicks on the menu entry. Here
gimp is, of course the name of the application, and
%f is a placeholder that will be substituted by the path of the first selected file. The other available placeholders are described in the interface itself.
We enabled startup notification for our custom action: this makes so that a spinning cursor is displayed while the action is being performed, so in this case while Gimp is launched. This is can be used as a feedback to notify the user that action has been launched.
In order for our custom action to be easily identified in the Thunar context menu, we decided to associate it with the “Gimp” icon. Next, In the “Appearance Conditions” tab, we established that the action should appear only when one or more images are selected, no matter their names:
To save our custom action, we just click on the “OK” button. The next time we select and right-click on an image, we should see the related entry in the context menu:
Creating custom actions with a text editor
In certain cases we may need to create a custom action programmatically, to automate our setup for example. The custom actions we create via the Thunar graphical interface are stored in the
~/.config/Thunar/uca.xml file. Here is the current content of the file on my system:
<?xml version="1.0" encoding="UTF-8"?> <actions> <action> <icon>utilities-terminal</icon> <name>Open Terminal Here</name> <unique-id>1671100132617415-1</unique-id> <command>exo-open --working-directory %f --launch TerminalEmulator</command> <description>Example for a custom action</description> <patterns>*</patterns> <startup-notify/> <directories/> </action> <action> <icon>gimp</icon> <name>Edit with Gimp</name> <unique-id>1671615960737911-1</unique-id> <command>gimp %f</command> <description>Edit selected image with Gimp</description> <patterns>*</patterns> <startup-notify/> <image-files/> </action> </actions>
As you can see, the root tag is
<actions>, and each custom actions is defined inside an
<action> tag. Actions are described with dedicated tags: the
<icon> tag, for example, contains the name of the icon associated with the action; same thing for the action name, description etc (the
<unique-id> tag is generated automatically). Boolean options are represented by self-closing tags, like
<image-files/>: using them is the equivalent of ticking the related checkboxes in the graphical interface.
In this tutorial we learned how to extend the functionalities of the Thunar file manager by creating custom actions. We saw how custom actions can be created directly from the Thunar interface and what are the fields that needs to be defined. We also created a custom action as an example, and, finally, we saw how custom action are stored in a simple text file, using the xml syntax. Thunar is not the only file manager which can be extended by using custom actions: take a look at our tutorial about extending PCManFM and Nautilus by creating extensions written in python and or custom scripts.