Configuring Shortcuts  Configuring Shortcuts   Configuring 4Pane  Configuring 4Pane   Devices and Editors  Devices and Editors

User-defined Tools

One of the good 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:

Sometimes you'll want finer control over which pane the items come from. For the 's', 'f', 'd' and 'a' parameters this can be done using the following modifiers (these examples use %s, but the other parameters could be substituted): Since 4Pane 6.0 you can also use: Note that some combinations aren't sensible (e.g. %3f: you can't select a file in a dir-view); and multiple modifiers aren't permitted (e.g. %A3d).

These parameters can be combined or repeated as appropriate e.g. ~/myscript %p %a %p will prompt the user for two string parameters, then pass these and all the currently selected items to myscript.
diff -u %2f %4f will diff two selected files, one from each file-view ("diff -u %b" or "diff -u %Af %If" would do the same if a file-view is active).
rsync -avu %3d/ %1d will update the contents of the selected directory in the left dir-view to match those of the right dir-view selection (the extra '/' is needed by rsync).

You can run a tool with superuser privileges without opening a terminal: tick the box when you Add the tool. However this ability is limited: the command should be one that quickly returns, e.g. fdisk %p, not one that will linger like kwrite %f; and as there's no terminal there is nowhere to display output, so there's no sense in doing something like fdisk -l. Instead try using an outside front-end such as kdesu or gksu e.g. kdesu kwrite %f; or in a terminal by prefixing 'su -c ' or 'sudo '.

The available user-defined commands can be run from the Tools > Run a Program menu or from the context menu. Alternatively you can give a tool a keyboard shortcut: see Configuring Shortcuts.





The Configure: Add a User-Defined Tool dialog, in Ubuntu
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.

The last tickbox is for when you want to run a program as root, and don't need to be shown any output; for example, creating a root-owned directory. If you do need to view output you must run in a terminal instead.

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.

Next 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.





The Configure: Edit a User-Defined Tool dialog, in Ubuntu





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").








The Configure: Delete a User-Defined Tool dialog, in Ubuntu





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.