Custom commands

For tips and help on how to customize various aspects of muCommander.

Custom commands

Postby Nicolas » Thu Mar 01, 2007 6:08 pm

In order to perform system dependant commands (executing files, opening the file manager, ...) muCommander uses custom commands.
For example, opening Mac OS X's file manager is done by executing open -a Finder on the current directory.
At boot time, muCommander tries to analyse which system it's running on and create the corresponding commands.

Since version 0.8 beta 3, it is possible for users to tweak these commands and change them to better fit their needs. This is achieved through two different configuration files: commands.xml and associations.xml. This section focuses on custom commands, but you can learn more about custom associations in another post.

The commands.xml file is located in your muCommander preferences folder, and looks something like this:
Code: Select all
<?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>


Commands declared in that file can be associated to specific file types (executable files, files that match .*java...), muCommander actions (open URL), and displayed in the contextual Open with... menu.

Each commands has up to 4 attributes:
- alias (compulsory). A command's alias is used to identify and reference it accross the system. It has to be unique, and if you're updating a command, it's always safer not to change its alias.
- value (compulsory). What will be executed when the command is triggered. You can use special tokens there: $f for the file's full path, $n for its name, $p for its parent directory and $j for the JVM's startup directory.
- type. This can be set to system, invisible or left unspecified. For the time being, it is safer to either leave that attribute unspecified or set it to invisible, the difference being that invisible commands won't appear in the Open with... menu.
- display. That's the name under which the application will be displayed to users - well, in the Open with... menu, really. If this attribute is not present, then the command's alias will be used when it's displayed.

Let's take a few examples to make that clearer.
Code: Select all
<command alias="Safari" value="open -a Safari $f"/>

This creates a new command which:
- will open a file in Safari.
- will be visible to users in the Open with... menu.
- will be refered to in the system as Safari.
- will be displayed to users as Safari

Code: Select all
<command alias="iexplorer" value="c:\Program Files\Internet Explorer\iexplore.exe $f" display="Internet Explorer"/>

This creates a new command which:
- will open a file in Internet Explorer.
- will be visible to users in the Open with... menu.
- will be refered to in the system as iexplorer.
- will be displayed to users as Internet Explorer.

Code: Select all
<command alias="textedit" value="/usr/bin/emacs $f" type="invisible"/>

This creates a new command which:
- will open a file in Emacs.
- will not be visible to users.
- will be refered to in the system as textedit.

From these examples, the importance of the alias attribute might not be obvious. There are, however, 4 hard-coded system aliases with very specific meanings for muCommander:
- open
- openURL
- openFM
- openEXE

open is used to open files. If it's defined and muCommander hasn't found a command that could open a specific file type, open will be used.
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 is 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 current 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 is 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 is 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, ...).

The default registered commands per system are:

MAC OS X:
Code: Select all
<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"/>


Windows 9x:
Code: Select all
<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"/>


Windows NT:
Code: Select all
<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"/>


*nix running on KDE:
Code: Select all
<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"/>


*nix running on Gnome:
Code: Select all
<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"/>


Anything else:
Code: Select all
<command alias="openEXE" type="system" value="$f"/>
User avatar
Nicolas
 
Posts: 831
Joined: Mon Oct 02, 2006 10:36 pm
Location: France

Postby peewack » Wed Jun 06, 2007 1:50 pm

Hi!

I'm adding the command for execute JAR files, but mucommander puts a copy of the JAR in the %temp% folder and from there executes it. How to execute a JAR file from its own path.

^^ thanx

PD: muCommander nightly 4th june, JRE 1.6.0_01-b06
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<commands>
    <command alias="playJar" value="javaw -jar $f" display="Abrir java jar"/>
</commands>
User avatar
peewack
 
Posts: 7
Joined: Wed May 16, 2007 11:33 am
Location: Valparaiso|Santiago Chile

Postby Nicolas » Wed Jun 06, 2007 2:04 pm

Mmm... could it be that you're trying to open remote JAR files, ie over anything other than the local file system?

If that's the case, there's nothing we can do, I'm afraid.
Let's take an example. Say the JAR you want to execute is located here:
http://www.mucommander.com/download/nig ... mander.jar

muCommander is perfectly fine with such a URL and will manage to load the file for you. I *highly* doubt your OS would be able to do the same thing :)
The only thing muCommander can do is copy the file locally, somewhere that won't confuse the OS, and *then* execute it.

Nicolas
User avatar
Nicolas
 
Posts: 831
Joined: Mon Oct 02, 2006 10:36 pm
Location: France

open applications with spaces in their names in OS X

Postby thrawn » Wed Aug 15, 2007 11:22 am

Hi,
I was trying to create open commands for Adobe Photoshop CS2
the command in the terminal looks like this
Code: Select all
open -a "Adobe Photoshop CS2" foo.jpg

so I tried the following command entries (all except 3 work from the command line):
Code: Select all
   <command alias="Photoshop1" value="open -a 'Adobe Photoshop CS2' $f"/>
   <command alias="Photoshop2" value='open -a "Adobe Photoshop CS2" $f'/>
   <command alias="Photoshop3" value="open -a Adobe Photoshop CS2 $f"/>
   <command alias="Photoshop4" value="open -a Adobe\ Photoshop\ CS2 $f"/>

neither worked, the entries appear in the open with menu, but if I run them nothing happens just as if I had tried to run:
Code: Select all
open -a Adobe Photoshop CS2 foo.jpg

on the command line which produces an error on the command line but does not open any application.

I guess you filter the variables somehow for special characters which prevents escaping characters in application names...
thrawn
 
Posts: 3
Joined: Wed Aug 15, 2007 11:06 am

Postby Nicolas » Wed Aug 15, 2007 11:29 am

And that's exactly why I need to get my act together and write the UI for this configuration file.

Your problem is that you're not writing legal XML here. Try the following:
Code: Select all
<command alias="Photoshop1" value="open -a &quot;Adobe Photoshop CS2&quot; $f"/>


Let me know how that works out for you.

Nicolas
User avatar
Nicolas
 
Posts: 831
Joined: Mon Oct 02, 2006 10:36 pm
Location: France

Postby thrawn » Wed Aug 15, 2007 11:44 am

Thanx for the quick reply!
I tried your suggestion with the same result.
And I am pretty sure that at least option2 is legal xml (that is what GoLive produced when I edited the value in Layout mode).
Mind you, this is an attribute declaration not xml content.

btw. I am running Mac OS X 10.4.10 with Java 1.5 (the latest stable version)

If you do not have a mac for testing, I am happy to help out...
Is there any way to see what the actual command is that muCommander is trying to run?

and one more thing: if I enclose any single command application name in any of the variants (as I said " ' ' " or ' " " ' should be valid and I tried " &quot; &quot; " for good measure) It does not work anymore either so somewhere muCommander rejects these values completely.
thrawn
 
Posts: 3
Joined: Wed Aug 15, 2007 11:06 am

Postby Nicolas » Wed Aug 15, 2007 2:23 pm

I'm afraid option 2 is definitely not valid XML :)
Attribute delimiters *have* to be " characters in the strict definition of the language, which we're enforcing in muCommander.

That being said, what you encountered is a bug. After refreshing my memory on that particular bit of code, Option 4 is the right way to go, but my parser somehow forgets to remove the \ characters.
This has been fixed, and should make its way in the nightly version by tonight.

Apologies for the inconvenience, and thanks for reporting it!
Nicolas
User avatar
Nicolas
 
Posts: 831
Joined: Mon Oct 02, 2006 10:36 pm
Location: France

Postby thrawn » Wed Aug 15, 2007 4:48 pm

Nicolas wrote:I'm afraid option 2 is definitely not valid XML :)
Attribute delimiters *have* to be " characters in the strict definition of the language, which we're enforcing in muCommander.

Not according to the w3c xml 1.1 specs:
http://www.w3.org/TR/2006/REC-xml11-20060816/#NT-AttValue
;-)
That being said, what you encountered is a bug. After refreshing my memory on that particular bit of code, Option 4 is the right way to go, but my parser somehow forgets to remove the \ characters.
This has been fixed, and should make its way in the nightly version by tonight.

Apologies for the inconvenience, and thanks for reporting it!
Nicolas

No inconvenience at all.
You are doing a great job and I am thoroughly impressed at how fast you responded.
Thanks a lot for this great program!
thrawn
 
Posts: 3
Joined: Wed Aug 15, 2007 11:06 am

Postby Nicolas » Wed Aug 15, 2007 8:45 pm

Woops, he he he, looks like I was wrong :)

Glad I could help, I only wish I hadn't made a bit of a fool of myself in the process :)

Nicolas
User avatar
Nicolas
 
Posts: 831
Joined: Mon Oct 02, 2006 10:36 pm
Location: France

Re: Custom commands

Postby jeppo » Fri Apr 18, 2008 6:52 pm

It is possible to use the intern "Run Command... (Strg+R)" command to see shell commands return values?

I use booth Linux and Windows an will have only 1 commands.xml.
On booth Systems i use the same tools ffmpeg, imagemagick, etc..
It would be nice when i can use the intern "Run Command" to see return values.

btw nice programm
great work devs
jeppo
 
Posts: 1
Joined: Fri Apr 18, 2008 6:13 pm

Re: Custom commands

Postby mrt181 » Tue Jun 24, 2008 10:36 am

hi, i can't find a commands.xml file on my system.

I created one in this directory:
Code: Select all
C:\cygwin\home\user\.mucommander\

because here are also other xml files:
    action_keymap.xml
    bookmarks.xml
    command_bar.xml
    extensions
    preferences.xml
    shell_history.xml
    themes
    toolbar.xml
    user_theme.xml

The custom commands.xml has the following content:

Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<commands>
   <command alias="textedit" value="C:\Programme\Emacs\bin\runemacs $f" type="invisible"/>
</commands>


i am probably doing something wrong but it is not possible to edit files with emacs instead of the built in editor.
mrt181
 
Posts: 3
Joined: Tue Jun 24, 2008 10:29 am

Re: Custom commands

Postby Vrho » Sun Aug 24, 2008 5:23 pm

Hi,

First I must say that muCommander is the best file browser I ever used.

But lets get to the point:
Open with... doesn't work in my muC

I followed the steps written above. I created a commands.xml file in my user files/.mucommander and the content is:
Code: Select all
<?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>


But my Open with... is still greyed.

I'm runing Win Xp Pro SP2, Java 6.

Thank you very much for help
Vrho
Vrho
 
Posts: 3
Joined: Sun Aug 24, 2008 5:05 pm

Re: Custom commands

Postby jhondrick@inbox.com » Tue Aug 26, 2008 12:35 am

I am using mu commander because it is completely keyboardable in a gui world, but really need the system context menu. The open with function is only a bandaid, but might satisfy the need if I could make it work.
But after I simply copied the example code, as above, I still have no success. The open with remains unavailable (0.8.2).
Please help.

Thanks,
Jack
jhondrick@inbox.com
 
Posts: 1
Joined: Tue Aug 26, 2008 12:22 am

Re: Custom commands

Postby Nicolas » Tue Aug 26, 2008 12:52 am

To answer the latests posts about this: creating a commands.xml file that contains the default values will *not* have any effect - these values would be the ones that muCommander uses when it can't find a commands.xml file.

Try having the following in your commands.xml file instead:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<commands>
   <command alias="Emacs" value="C:\Program Files\Emacs\bin\runemacs $f"/>
</commands>


This will register a new command called Emacs. It will appear in the Open with... menu and will trigger emacs when activated, provided the runemacs script is in the right location.

Also, if you're not going to modify the default values, it's much safer not to declare them in commands.xml. Doing so has no benefit and might cause issues with later versions of muCommander.

Hope this helped!
Nicolas
User avatar
Nicolas
 
Posts: 831
Joined: Mon Oct 02, 2006 10:36 pm
Location: France

Re: Custom commands

Postby Nicolas » Tue Aug 26, 2008 12:58 am

Oh, and to reply to mrt181:
- you're absolutely right, this is how to create a custom commands.xml file.
- on the other hand, that's not the way to replace the internal editor. In order to do that, have a look at that thread: http://www.mucommander.com/forums/viewtopic.php?f=2&t=416&st=0&sk=t&sd=a (scroll a bit to the bottom of the first page).

This should sort you out.

Cheers,
Nicolas
User avatar
Nicolas
 
Posts: 831
Joined: Mon Oct 02, 2006 10:36 pm
Location: France

Next

Return to Pimp my commander

Who is online

Users browsing this forum: TeelaHaph and 2 guests

cron