Custom Commands - elemongw/mucommander GitHub Wiki

Introduction

Custom commands are what muCommander uses to interract with your system. Typical actions that involve custom commands are:

  • opening a file.
  • opening a URL.
  • starting the system's default file manager.

This page explains the format of the commands.xml customisation file, and how you can use it to configure muCommander to better suit your needs.

If you need help in figuring out where your commands.xml file is located, read this.

Why would I want to mess with this?

Well, the most common reason to do so is that custom commands will appear in your Open With... contextual menu. While muCommander will use the application associated with a file when opening it, this is not always the desired action: say, for example, that you have a text file that you want to e-mail someone. Opening it the normal way would start your text editor, while creating a custom Mail command could automatically create a new e-mail with that file as an attachment.

Another reason to tweak your custom commands is that you might not be happy with system defaults. I'm personally using this as a workaround to an odd OS X bug: however often I tell it that XML files should be opened with Emacs, it insists on triggering Dashcode, which annoys me to no end. Using custom commands (and custom associations?), I was able to override this frustrating behaviour.

Finally, some users are fairly unhappy with the internal file viewer and file editor. Should this be your case, you can modify your commands.xml file to use whatever software you want for file viewing and edition.

Custom commands format

Your custom commands file should look something like:

<?xml version="1.0" encoding="UTF-8"?>
<commands>
    <command alias="Safari"  value="open -a Safari $f"/>
    <command alias="Mail"    value="open -a Mail $f"/>
    <command alias="Preview" value="open -a Preview $f"/>
    <command alias="open"    value="open $f"            type="system"/>
    <command alias="openFM"  value="open -a Finder $f"  type="system" display="Finder"/>
    <command alias="openURL" value="open $f"            type="system"/>
</commands>

For people who can read XML, this is fairly simple:

  • The root element is always commands. It doesn't accept attributes. It can contain any number of command elements.
  • The command element accepts 4 attributes, alias, value, type and display.

For the others, it doesn't really matter. If you want to create a new custom command, just copy one of the lines that start with <command... and edit it according to the rules I'll be outlining bellow.

alias attribute (compulsory)

A command's alias is the name under which muCommander will know and display it (note that this isn't strictly correct, see display for more details). When giving a name to a custom command, you should try to make it something meaningful, such as Safari for Apple's Web browser.

While there are no real constraints on a command's alias, you should avoid the following values:

  • open
  • openURL
  • openFM
  • openEXE
  • view
  • edit

These aliases have a special meaning for muCommand and shouldn't be modified unless you know what you're about. Read this for more information.

value attribute (compulsory)

General syntax

That's the system command to execute when your custom command is called. Just type in the command as you would in a Shell. For example:

  • open -a Safari: opens the Safari web browser under OS X.
  • /usr/bin/emacs: opens Emacs under Unix systems.

Keywords

You can use the following keywords:

Keyword Replaced with Example
$f The full path of the currently selected file. /tmp/mucommander/readme.txt
$n The name of the currently selected file. readme.txt
$p The path of the currently selected file's parent. /tmp/mucommander
$j The path of the directory from which muCommander was started. /Users/joesmith
$e The extension of the currently selected file (or the empty string if none) txt
$b The name of the currently selected file, without its extension. readme

For example:

  • open -a Safari $f: opens the currently selected file with Safari.
  • /usr/bin/emacs $f: opens the currently selected file with Emacs.

Character escaping

A common pitfall when writing a custom command's value attribute is whitespaces: muCommander uses them to separate a command from its arguments. If you must write a path that contains spaces - typically, My Documents - make sure to escape them. This can be achieved in two ways:

Single character escaping: \ (backslash). This will prevent muCommander from interpreting the following character. Multiple character escaping: " (double quote). Any string enclosed by two such characters won't be interpreted by muCommander. Additionally, you must be careful to respect XML entities: the " (double quote) character, for example, should be written ".

For example:

  • c:\Documents\ And\ Settings\Software.exe $f: opens the currently selected file using a software located in c:\Documents And Settings.
  • &quot&;c:\Documents And Setting\Software.exe" $f: same as the above, but using a different escaping strategy.

type attribute

This is really meant for muCommander's internal workings, and is better left alone. The one case where you might want to use this is to set it to invisible in order to prevent your command from appearing in the Open With... contextual menu.

display attribute

This is used to overwrite the custom command's alias when it's displayed, typically in the Open With... contextual menu. For example:

  • will create a command displayed as Safari in the contextual menu.
  • will create a command displayed as Browser in the contextual menu.

Special commands

We briefly talked about special command aliases earlier. This is where we detail these.

When present, user defined values for these commands will always be used. Otherwise, muCommander will attempt to find usable defaults, either through predefined values for known systems or through the Java Desktop API.

open

Command used to open files. Unless you have defined specific custom associations?, this is what will be executed when you press enter in muCommander.

Note that if it's not defined, odds are that muCommander will be fairly useless. We're trying to provide working default values for known systems, but if you find yourself in a situation where muCommander just won't open files, you might need to find your system's 'file opener' and register it as the open command.

openEXE

Command used to open executable files. Under most known systems, there is no need to have a special case for executable files, but if muCommander finds itself running on an unknown environment, it will assume that executable files should be opened using the openEXE command. It's default value is $f (run the file itself), but if that doesn't work on your system, you can toy around with openEXE's value to fix this.

Due to Sun's tardiveness in supporting file permissions, muCommander will only be able to decide whether a file is in a fact an executable or not if you're running under Java 1.6 or later. If you're not, muCommander will assume that any file that doesn't have an extension is an executable. We suggest that you upgrade your Java version.

openFM

Used by muCommander when it needs to open a file in the system's File Manager. If this command is not defined, the Reveal in Deskop action will be disabled. This is the only system command that needs a display attribute.

openURL

Used by muCommander when it needs to open an URL in the system's default browser. If this command is not defined, all actions that involve opening an URL will be disabled (Go to homepage, Download new version, ...).

view

Used by muCommander when 'viewing' a file (action mapped to F3 by default). If not set, the internal file viewer will be used.

edit

Used by muCommander when 'editing' a file (action mapped to F4 by default). If not set, the internal file editor will be used.

Note that if you do set an edit command, you loose one fairly important feature: while the internal editor knows how to write remote files, custom editors work on local copies only and the modifications won't be saved on the remote computer.

Default commands

This section lists default custom commands per system. You can use these as a base for customisation, or to get a deeper understanding at the way muCommander works. Or you might to suggest better default commands, if you dislike the way muCommander behaves on your system.

MAC OS X

<?xml version="1.0" encoding="UTF-8"?>
<commands>
    <command alias="open"    type="system" value="open $f"/>
    <command alias="openURL" type="system" value="open $f"/>
    <command alias="openFM"  type="system" value="open -a Finder $f" display="Finder"/>
</commands>

Windows 9x

<?xml version="1.0" encoding="UTF-8"?>
<commands>
    <command alias="open"    type="system" value="start &quot;$f&quot;"/>
    <command alias="openURL" type="system" value="start &quot;$f&quot;"/>
    <command alias="openFM"  type="system" value="start &quot;$f&quot;" display="Explorer"/>
</commands>

Windows NT

<?xml version="1.0" encoding="UTF-8"?>
<commands>
    <command alias="open"    type="system" value="cmd /c start &quot;&quot; &quot;$f&quot;"/>
    <command alias="openURL" type="system" value="cmd /c start &quot;&quot; &quot;$f&quot;"/>
    <command alias="openFM"  type="system" value="cmd /c start &quot;&quot; &quot;$f&quot;" display="Explorer"/>
    <command alias="openEXE" type="system" value="cmd /c $f"/>
</commands>

*nix running on KDE

<?xml version="1.0" encoding="UTF-8"?>
<commands>
    <command alias="open"    type="system" value="kfmclient exec $f"/>
    <command alias="openURL" type="system" value="kfmclient openURL $f"/>
    <command alias="openFM"  type="system" value="kfmclient exec $f" display="Konqueror"/>
</commands>

*nix running on Gnome

<?xml version="1.0" encoding="UTF-8"?>
<commands>
    <command alias="open"    type="system" value="gnome-open $f"/>
    <command alias="openURL" type="system" value="gnome-open $f"/>
    <command alias="openFM"  type="system" value="gnome-open $f" display="Nautilus"/>
    <command alias="openEXE" type="system" value="$f"/>
</commands>

Anything else

<?xml version="1.0" encoding="UTF-8"?>
<commands>
    <command alias="openEXE" type="system" value="$f"/>
</commands>
⚠️ **GitHub.com Fallback** ⚠️