# What action should be executed ?

You most probably want that your action eventually ends up in executing something. And, as a matter of fact, having something to execute is one of the few conditions which are required for an action to be considered as valid.

As we have already seen, the command to be executed is configured in the Command page.

This command may take arguments, which themselves may embed parameters. These parameters will be expanded at runtime, with values which will depend on currently selected item(s).

## Available parameters

In the Command page, click on Legend button to see the list of available parameters.

### List of available parameters

Shows the list of available parameters.

The available parameters

The Legend button has a toggling action: click once to display the Parameter Legend dialog box; click a second time to hide it.

The word &laquosp;first&spraquo; may be misleading as it only refers to the list of selected items internally provided by the file manager to the &prodname; plugin.

In particular, it has nothing to do with the visual selection you may have done in the file manager window. And, in fact, which is the &laquosp;first&spraquo; selected item in a multiple selection is absolutely undefined and rather unpredictable.

## Where the action should it be executed ?

Your action may be executed in a particular working directory.

You may specify it in the Command tab, in the Working directory entry box, or by clicking on Browse to select a folder on the filesystem.

### Working directory frame

Focus on the working directory selection frame.

Working directory frame

The working directory defaults to `%d`, which runs the command in the base directory of the (first) selected item.

In the particular case of the `%d` parameter, the &laquosp;first&spraquo; selected item is not very important because it is very likely that all selected items are located in the same base directory.

## How should the action be executed ?

Apart from configuring the conditions, the selection must be met in order your action be displayed in file manager menus, &prodname; allows you to configure how exactly your command will be executed.

Click on the Execution tab to show the page which configures the execution of your command.

### Configuration of the execution modes

Shows how to configure the execution modes of a command.

Configuration of the execution modes

### Execution mode

#### Configuration of the execution mode

Focus on the execution mode frame.

Configuration of the execution mode

The execution mode of your command may be chosen between following values:

Normal

  Starts the command as a standard graphical user interface.

Terminal

  Starts the preferred terminal of the desktop environment, and runs the command in it.

Embedded

  Makes use of a special feature of the file manager which may allow a terminal to be ran in it.

  As &nautilus; does not have this feature, this option is strictly equivalent to `Terminal` option.

Display output

  Starts the preferred terminal of the desktop environment, and runs the command in it. At end, standard streams (stdout, stderr) are collected and displayed.

The execution mode of a command defaults to `Normal`. That is, the command is executed without any particular pre- or post-work.

### Startup notification

#### Configuration of the startup modes

Focus on the Startup mode frame.

Configuration of the startup modes

If the execution mode of the command is `Normal`, and if you know that the application will send a `remove` message with the `DESKTOP_STARTUP_ID` environment variable set, then check the Startup notify checkbox.

See the Startup Notification Protocol Specification for more details.

### Window class

If the execution mode of the command is `Normal`, and if you know that the application will map at least one window with a given class name, then enter that name into the Startup Window Manager class entry box.

See the Startup Notification Protocol Specification for more details.

### Owner of the execution

#### Configuration of the owner of the run

Focus on the Execute as frame.

Configuration of the owner of the run

Enter in the Execute as user entry box the username or the UID of the user your command will be run as.

If you do not enter anything in this field, then the command will be executed as the current user.

### Multiple executions

You may want your command to be executed once, providing it the list of selected items as argument.

Or you may prefer your command to be repeated for each selected item, providing a different item as argument for each execution.

Actually, &prodname; automatically handles these two behaviors, depending of the form and the order of the parameters in the command arguments.

Though some parameters are not depending on the count of the selection (e.g. &laquosp;`%c`&spraquo;, the selection count itself), most have two declensions:

- a &laquosp;singular&spraquo; one, e.g. &laquosp;`%b`&spraquo;, the basename of the selected item;

- a &laquosp;plural&spraquo; one, e.g. &laquosp;`%B`&spraquo;, the space-separated list of the basenames of selected items.

When the selection is empty or contains only one element, and from this topic point of view, these two forms are exactly equivalent.

When the selection contains more than one item:

- if the first relevant parameter is of a singular form, then &prodname; will consider that the command is only able to deal with one item at a time, and thus that it has to be ran one time for each selected item;

- contrarily, if the first relevant parameter found is of the plural form, then &prodname; will consider that the command is able to deal with a list of items, and thus the command will be executed only once;

- if all found parameters are irrelevant, then &prodname; defaults to consider that the command should be executed only once.

#### Characterization of the parameters vs. multiple execution

Parameter | Description | Repetition
--- | --- | ---
`%b` | (first) basename | singular |  |
`%B` | space-separated list of basenames |  |  | plural
`%c` | count of selected items |  | irrelevant |
`%d` | (first) base directory | singular |  |
`%D` | space-separated list of base directory of each selected items |  |  | plural
`%f` | (first) filename | singular |  |
`%F` | space-separated list of selected filenames |  |  | plural
`%h` | hostname of the (first) URI |  | irrelevant |
`%m` | mimetype of the (first) selected item | singular |  |
`%M` | space-separated list of the mimetypes of the selected items |  |  | plural
`%n` | username of the (first) URI |  | irrelevant |
`%o` | no-op operator which forces a singular form of execution | singular |  |
`%O` | no-op operator which forces a plural form of execution |  |  | plural
`%p` | port number of the (first) URI |  | irrelevant |
`%s` | scheme of the (first) URI |  | irrelevant |
`%u` | (first) URI | singular |  |
`%U` | space-separated list of selected URIs |  |  | plural
`%w` | (first) basename without the extension | singular |  |
`%W` | space-separated list of basenames without their extension |  |  | plural
`%x` | (first) extension | singular |  |
`%X` | space-separated list of extensions |  |  | plural
`%%` | the &laquosp;`%`&spraquo; character |  | irrelevant |

#### Usage of singular vs. plural forms

Say the current folder is `/data`, and the current selection contains the three files `pierre`, `paul` and `jacques`.

#### If we have requested `echo %b`,

then the following commands will be successively run:

- `echo pierre`
- `echo paul`
- `echo jacques`

This is because `%b` marks a singular parameter. The command is then run once for each of the selected items.

#### Contrarily, if we have requested `echo %B`,

then the following command will be run:

- `echo pierre paul jacques`

This is because `%B` marks a plural parameter. The command is then run only once, with the list of selected items as arguments.

#### If we have requested `echo %b %B`,

then the following commands will be successively run:

- `echo pierre pierre paul jacques`
- `echo paul pierre paul jacques`
- `echo jacques pierre paul jacques`

This is because the first relevant parameter is `%b`, and so the command is run once for each selected item, replacing at each occurrence the `%b` parameter with the corresponding item. The second parameter is computed and added as arguments to the executed command.

#### And if we have requested `echo %B %b`,

then the following commands will be run:

- `echo pierre paul jacques pierre`

This is because the first relevant parameter here is `%B`. The command is then run only once, replacing `%B` with the space-separated list of basenames. As the command is only run once, the `%b` is substituted only once with the (first) basename.