User-defined Tools
One of the nice things about using a gui file manager is being able to select several files, then do something to them e.g. rename or delete them.
But rename etc has to be built into the file manager. Wouldn't it be nice if it were possible to extend this idea to process selected files
using commands of your own. Well with 4Pane you can do exactly this. A user-defined tool can call any available commands or scripts, to which you can pass selected items as parameters.
Though you can run programs that don't need parameters, such as 'df -h', you'll usually want to use them. This is how:
- %s is replaced by a Single selected file or directory.
- %f is replaced by a single selected File only; directories are ignored.
- %d is replaced by a single selected Directory only; files are ignored.
- %a is replaced by All the items selected in the active pane.
- %b is replaced by a single selected item from Both of the file-views.
- %p will prompt the user for a Parameter to pass to the application at run-time.
- %% is replaced by %, in case you need to use one in a script.
These can be combined or repeated as appropriate e.g. "~/myscript %p %p %a" will prompt the user for two parameters, then pass these and all the currently selected items to myscript.
You will probably be able run applications with superuser privileges by putting kdesu or gksu before the command e.g. "kdesu kwrite %f".
Similarly, depending on your setup, you may be able to run commands in a terminal by prefixing "sudo ".
The available user-defined commands can be run from the Tools > Run a Program menu. Alternatively you can give a tool a keyboard shortcut: see Configuring Shortcuts.
Add a new tool
4Pane comes with a "starter-pack" of these tools, but the idea is to add your own. You can do this in the Tools section of Options > Configure 4Pane.
In the first box of the Add a tool sub-page, type in the full command e.g. myscript %f %p.
If the command needs to run in a terminal e.g. df -h, tick the "Run in Terminal" tickbox below. Some terminal commands (again df -h is a good example) display their output in the terminal, then immediately close before you can read the results.
To prevent this, tick the "Keep terminal open" box.
The next two tick-boxes are 'Refresh pane after' and 'Refresh opposite pane too'. They are for commands that don't run in a terminal, and tell 4Pane to update either the current pane,
or both of them, once the command has finished running.
You'd want this for a command that affects the files in one of the visible panes. For example, this mini-script uses imageMagick to resize all the selected files to quarter-size:
for image in %a; do path=`dirname ${image}` && filename=`basename ${image}` && name=`echo ${filename} | cut -d\'.\' -f1` && ext=`echo ${filename} | cut -d\'.\' -f2` && convert ${image} -resize 25%% ${path}/${name}-25%%.${ext}; done
You'd like to be able to see that the size of the files has changed when the command has finished running, so tell 4Pane to update the current pane by ticking the
'Refresh pane after' box.
In the second box type the label: the words that you want to be seen in the Tools menu; if you leave this blank, the command itself will be used.
Lastly you need to choose to which menu or submenu the command should be added. The default is Run a Program, but you can also select any available submenus.
You can create a new submenu, or delete the currently selected one, using the buttons on the right.
Edit an existing tool
The next sub-page lets you edit existing tools. Select from the dropdown box the label of the tool to be edited;
the command and "in terminal" etc status will be shown below. When you have the correct tool selected. click the "Edit this Command" button.
You will then be able to alter any of the entries. When you've finished click the button again (it will have changed its label to "Click when finished").
Delete an existing tool
The last sub-page handles deletion. Select the tool to delete from the dropdown box, then click the "Delete this command" button.
An "Are you sure" dialog will appear, to allow you to change your mind.
Once the data has changed, the Apply and Cancel buttons become enabled. When you've finished all your alterations,
click "Apply" (or Cancel if you've changed your mind). Until you do this, the results are not saved.
If you've finished configuring, click "Finished" to close the Configure dialog.