Custom Actions

Thunar allows users to add custom actions to the file and folder context menus (by the use of the thunar-uca plugin, part of the Thunar distribution, in the plugins/ subdirectory). You can set up new actions in the Custom Actions dialog, available via the Configure custom actions... item in the Edit menu.

This page serves as an introduction to the Custom Actions plugin, and includes a list of useful examples.

Adding a Custom Action

This section provides a step-by-step introduction to the Custom Actions plugin, demonstrating how to add a Print File action, which uses xfprint to print text files. We start by opening the Custom Actions dialog as explained above. In the dialog, click on the first button in the list of buttons (the one labeled with the +). The Create Action dialog will appear, as shown in the screenshot below.

Create Action Dialog

On the first page, enter Print File in Name: and Print the selected file using xfprint in Description: Enter xfprint4 %f for the Command: (the %f will be replaced with the path to the selected file, as explained in the dialog), and select an icon by clicking Icon: (in the screenshot the printer-symbolic.svg icon was used).

Thunar seems to do the sensible thing when passing file/folder names with spaces in them, so don't worry excessively about putting single or double quotes around the “%” placeholder.

Now, continue with the second page (the Appearance Conditions page).

We want to create an action that is only applicable to text files, so select the Text Files options and unselect the options for the other file types. Next you can specify a File Pattern to display the action only for text files that match a certain pattern. In the example, we set the file pattern to * (which matches all filenames) to indicate that the action should be displayed for all text files.

That's all. Click OK to close the Create Action dialog. The new action, labeled Print File will appear in the Custom Actions list.

Now close the Custom Actions dialog, select a text file in Thunar and open the context menu (right-click on the file icon). The newly created Print File action will appear in the context menu, as shown in the screenshot below.

Custom Actions Dialog

You can use the thunar-dev mailinglist to get in touch with the developers, if you have questions about this short tutorial or custom actions in general.

Examples

Here are a few useful examples of custom actions. Feel free to extend this list.

Finding files in the current folder

Name: Search…

Command: gnome-search-tool –path=%f

File pattern: *

Appears if selection contains: Directories

Note: For this action, you'll need to have gnome-search-tool installed, which is part of the gnome-utils package. This program also has a lot of other nice command-line options which you could use to create even more specialized actions.

Finding files in the current folder with catfish

Name: Search files…

Command: catfish --path=%f

File pattern: *

Appears if selection contains: Directories

Note: For this action, you'll need to have catfish installed, which is part of the catfish package.

Finding files inside the selected folder with catfish

Name: Search files inside…

Command: catfish --path=%f%d

File pattern: *

Appears if selection contains: Directories

Note: For this action, you'll need to have catfish installed, which is part of the catfish package.

Working with archives (tar, gzip, etc)

Name: Extract here (bzip2)

Command: tar xjf %n

File pattern: *.tar.bz2;*.tbz2

Appears if selection contains: Other Files

Name: Extract here (zip)

Command: unzip %f

File pattern: *.zip

Appears if selection contains: Other Files

Name: Create tar.gz from folder

Command: tar czvf %n.tar.gz %n

File pattern: *

Appears if selection contains: Directories

Hint: You may prefer the Thunar Archive Plugin, which does pretty much the same thing with less manual setup required on your part. It's either included with your distribution (in the case of Xubuntu), or available as a separate package (thunar-archive-plugin in Debian Etch). You might also need the xarchiver or “squeeze” package for things to work quite right.

Playing music files

Name: Play with XMMS

Command: xmms %F

File pattern: *

Appears if selection contains: Directories, Audio Files

Name: Enqueue in XMMS

Command: xmms -e %F

File pattern: *

Appears if selection contains: Directories, Audio Files

Hint: Works exactly the same with Audacious.

Burning an ISO file to a CD

Name: Burn with K3B

Command: k3b --cdimage %f

File pattern: *.iso

Appears if selection contains: Other Files

Viewing images

Name: View with GQview

Command: gqview %f

File pattern: *

Appears if selection contains: Directories, Image Files

Note: This tip also works just as well with GThumb

Converting PNGs to JPEGs

Name: To JPEG

Command: convert %f -quality 75 %f.jpg

File pattern: *.png

Appears if selection contains: Image Files

Hint:`basename %f .png`.jpg (be careful–those are backticks) will strip the old .png extension off of the original filename.

Note: jpegtran is available as part of the libjpeg or libjpeg-progs packages of most distributions. Unlike using “convert”, the complicated loop structure is necessary with “jpegtran”: “jpegtran -rotate 90 -outfile %F %F” will produce a 0kb file.

Opening a terminal

Name: Open in a terminal

Command: terminal --default-working-directory=%d

File pattern: *

Appears if selection contains: Directories

Note: You might need to type xfce4-terminal instead of just terminal for some distributions.

Note: You will need python-periscope package. Get it here. You'll also need zenity package. This command will try to get the English subtitles, change -l en to something else (fr, de, pt-br, …). You should rewrite the command with normal straight quotes.

Rename subtitles easily

Name: Rename subtitles

Description: Select video and subtitles file. Subtiles will be reanmed based on the video name.

Command: subrnm %F

File pattern: *.avi;*.mp4;*.crdownload;*.srt;*.sub

Appears if selection contains: Video Files, Text Files, Other Files

Note: You will need subrnm script. Get it here. You'll also need zenity package.