
Thunar - XFCE & XUbuntu’s small but perfectly formed file manager - has a simple mechanism that allows you to easily add new commands to the right click menu of files and folders. These are called Custom Actions and are easy to create… here’s how to do it.
Click the Edit menu, then click ‘Configure custom actions…‘. This will take you to the Custom Actions Manager, where you can create, edit or delete your custom actions.
You can enter anything into the command box, including complex bash scripts, names of scripts or executables on the PATH, or the full path and filename of the command you want to run.

On the ‘Appearance Conditions‘ tab, you tell Thunar when you want your item to appear in the right click menu:

I’ve included my custom actions below - and you can find more around the web. I’ve only included ones here that aren’t commonly listed elsewhere.
But first, a word about Working Directories & Variables
Working Directory
The current working directory for the a custom action, is the folder the Thunar window that launched the action, is currently displaying. You can test this by creating and running the following custom action:
Test CWD
- Description
- Prints out the current working directory
- Command
pwd | zenity --text-info
- File Pattern
*
- Appears if selection contains
- Directories
- Requirements
sudo apt-get install zenity
This means that you can use just filenames without a path in your custom actions to refer to a file in the current folder. This means that you can use the %N
variable to process a list of selected files, instead if having to use the %F
variable which includes the full pathname - this is handy for renaming just the files, without tampering with the pathname, for example.
Variables
Thunar custom actions can contain variable parameters, that get substituted with the actual value when you run the action. These allow you to refer to the files that are currently selected in Thunar when running your actions, without knowing in advance which ones. The following variables are available:
This… | is replaced at runtime with this… |
---|---|
%f | The path to the first selected file |
%F | The paths to all the selected files |
%d | Directory containing the file referred to by %f |
%D | Directories containing the files referred to by %F |
%n | The first selected filename, without the path |
%N | All the selected filenames, without paths |
You can see examples of these variables in use below.
My Thunar Custom Actions
To use these yourself, copy and paste these names, descriptions & commands into new actions in your Custom Actions Manager:
Share Folder
- Description
- Shares the currently selected folder, giving everyone read access.
- Command
net usershare add %n %f "" Everyone:R guest_ok=y
- File Pattern
*
- Appears if selection contains
- Directories
Flatten Folder
- Description
- Moves all files from sub-folders to parent (current) folder, then removes all empty folders inside the current folder.
- Command
find . -mindepth 2 -type f -exec mv "{}" . \; && find . -type d -empty -delete
- File Pattern
*
- Appears if selection contains
- Directories
Rename to lower-case
- Description
- Rename the currently selected files, making the filenames lower-case.
- Command
for file in %N; do mv "$file" "$(echo "$file" | tr '[:upper:]' '[:lower:]')"; done
- File Pattern
*
- Appears if selection contains
- All
Slugify Filename
- Description
- Rename the currently selected files, making the filenames lower-case & replacing spaces with dashes.
- Command
for file in %N; do mv "$file" "$(echo "$file" | tr -s ' ' | tr ' A-Z' '-a-z' | tr -s '-' | tr -c '[:alnum:][:cntrl:].' '-')"; done
- File Pattern
*
- Appears if selection contains
- All
Copy Contents to Clipboard
- Description
- Copies the contents of the selected file to the clipboard.
- Command
cat "%F" | xclip -i -selection clipboard
- File Pattern
*
- Appears if selection contains
- Text Files
- Requirements
sudo apt-get install xclip
Compare
- Description
- Compares selected files or folders in Meld
- Command
meld %F
- File Pattern
*
- Appears if selection contains
- Directories, Text Files
- Requirements
- Either get the latest version of meld like this, or install the version in your distributions repository:
sudo apt-get install meld
Compress with Advpng
- Description
- Runs Advpng on each of the selected PNG Files.
- Command
for file in %F; do advpng -z -4 -q "$file"; done
- File Pattern
*.png
- Appears if selection contains
- Image Files
- Requirements
sudo apt-get install advancecomp
Quantize with pngnq
- Description
- Reduce to 8bit colour, by running pngnq on each of the selected PNG Files.
- Command
for file in %F; do pngnq -s1 "$file"; done
- File Pattern
*.png
- Appears if selection contains
- Image Files
- Requirements
sudo apt-get install pngnq
Optimize with jpegoptim
- Description
- Losslessly optimize JPEGs, by optimizing the Huffman tables and stripping comments and EXIF metadata from the file.
- Command
for file in %F; do jpegoptim --strip-all -of "$file"; done
- File Pattern
.jpg;.jpeg
- Appears if selection contains
- Image Files
- Requirements
sudo apt-get install jpegoptim
Related Posts
How to set your Compose Key on XFCE/Xubuntu & LXDE Linux
- The compose key on Linux is _incredibly_ useful, but not set by default - and on XFCE there's currently no GUI to change it. Here's how to do it...
How to switch to Compton for beautiful tear free compositing in XFCE
- How to quickly & easily setup & configure Compton in XFCE for beautiful, tear free, glassy smooth window dragging, drop shadows, etc...
How to create thumbnails for PDFs with ImageMagick on Linux
- How to create image thumbnails for PDFs, on Linux, using ImageMagick - a simple explanation, with examples.
Comprehensive Linux Backups with etckeeper & backupninja
- Having an easy to setup, comprehensive, automated backup strategy is very relaxing - here's how to create one.