This post is intended for you fellow users of Xfce, a window manager and suite of applications.
The Thunar file browser is a very interesting of these applications:
- It is extremely lightweight.
- It has a pleasant interface.
The one awesome feature we discuss here is about incrementing your configuration with custom actions for files and directories that are made accessible via their context menu.
- Open Thunar.
- Go to Edit -> Configure custom actions…
- Click on the “+” button on the right hand side of the dialog window (see the figure below).
- Now give in the name, description and choose the icon for your action.
Insert a command of yours to do something. In my case, I want to rename files so that they do not have special characters. I will do this by invoking the xfce4-terminal (obviously, also from the Xfce suite of applications) which in turn invokes bash with its -c option (which receives an argument string comprised of commands to be evaluated i.e. executed).
Here ‘s the code:
xfce4-terminal -x bash -c '/path_to_script/renameok.sh %f'
The script renameok.sh iterates through directories renaming their files stripping special characters. Soon a post will be included containing its source code and explanation.
If your script (generally referred to as script.sh instead of the specific renameok.sh) depends on stuff setup in .bashrc (the shell resource file) then just call bash with -i (bash -ic “command(s)”) which sets the interactive mode on and calls the resource file before executing the -c option commands. Also realize that when in an interactive session, if script.sh is in a PATH setup by .bashrc you are safe to remove the /path_to_script/ part of script.sh ‘s call as it will be thus found. And last, as my .bashrc can have some echo commands in it, I will deliberately add a clear command before the script call so that the resulting code will look like:
xfce4-terminal -x bash -ic 'clear; renameok.sh %f'
Now, in the Appearance Conditions tab uncheck every options but Directories as in this example we use the directory in which the context menu was invoked as the script ‘s argument (as it wants a directory path). This indeed causes the action to be available only for directories’ context menus in Thunar. The main purpose in this tab is for you to choose which type(s) of files (directories are a type of file) you want the action to be executable.
In the custom action entry edition dialog, still, notice the bottom of the window, which explains the meanings of the expansions including the %f shown in the examples herein. One interesting and awesome thing is that Thunar is also smart enough to realize that the actions must not be made available if more than one file (or directory, as in these examples) are selected in case you are using %f. Conversely, the action is selectable both for just one file or for multiple files when using %F instead.
To know more check the official wiki entry.