Today I bring you the Nuxeo Shell. This is a wonderful toolbox for developers and administrators and I think it deserves more recognition.

Opening the Shell Opening the Shell

Playing with the Shell

Using the Shell is quite easy when you have Nuxeo IDE. You need to be in the Nuxeo perspective and click on the little shell icon on the bottom left of the screen.

You can now type tab to see a list of the available commands. These commands are sorted by namespaces. Namespaces are command registries that you can register in the shell. A command registry helps bring inside the shell a new set of commands for a specific context without having name clash problems with already existing commands. It is also very useful because you have a different type of completion for each namespace. For instance, if you have selected the local namespace, hitting tab after ls will show you the list of files from your file system. If you have selected the remote namespace, it will display the list of documents on the Nuxeo server you are connected to.

So let's start with the connect command:

connect http://localhost:8080/nuxeo/site/automation/ -u Administrator

This command will prompt you for the password of the adminstrator user on the localhost:8080/nuxeo server.

Connect to the Shell Connect to the Shell

If you type tab again, you'll see that the command list has changed. There are a lot more of them. If you are a Unix shell user, it should feel like home. You'll recognize some of them: cat, ls, mkdir, mv, cp, rm. They will of course apply to the server's documents since you have selected the remote namespace. Let's try the ls and then cat /default-domain command.

Cat command example Cat command example

Do you need more information than what cat just gave you? Try help cat. Here is the description of the cat command, its syntax, options and arguments. This works with every command (you can also type cmds or commands to get the list of available commands). Try cat -all /default-domain, you'll see much more information. Keep on playing with the commands, you'll see you can do some pretty wicked things. Don't hesitate to browse the index of all command sorted by namespace on our wiki.

Content Automation

So all the commands you typed in the remote namespace are using the Content Automation API. That's right, you are using an http shell. This means I have two pieces of good news for you. The first is that you can call any existing operation or chain on the server. Just type use automation and you'll get in the right namespace. If you type tab for completion, you'll get the list of Operations and Operation Chains available on the server. If you don't know hos to use them, here's a quick trick. You can generate a help file for any name space using the following command: help -export [file] -ns [namespace]? This will give you the parameter name for each operation, for example. Then you'll know how to run Document.Query:

[email protected]:/> use automation
remote -> automation
> Document.Query -query "Select * From File"

The second piece of good news is that those operations are really easy to deploy on your server using NuxeoIDE. I've created a CountWords operation that counts the number of words contained in a document. You can check this out on a previous blog. It makes it quick and easy to test your operation directly from the IDE.

Groovy or MVEL script?

If you don't have the IDE, you can still use the shell. It's available from our nexus repository and has the exact same functionality as the one in the IDE. You'll probably miss being able to quickly execute an operation and reload it on the server. Well, there is an alternative to this workflow. You can execute Groovy or MVEL script. Those of you who are familiar with NuxeoStudio probably already know MVEL. For those who don't :

"MVEL is a powerful expression language for Java-based applications. It provides a plethora of features and is suited for everything from the smallest property binding and extraction, to full blown scripts."

Here are two small example of what you can do:

This is a complete example of a script used by the perms command to get the ACLs available on a document:

import org.nuxeo.ecm.core.api.PathRef;
import org.nuxeo.ecm.core.api.IdRef;

def doc = null;
def aclname = Context["acl"];
def ref = Context["ref"];
if (ref.startsWith("/")) {
doc = Session.getDocument(new PathRef(ref));
} else {
doc = Session.getDocument(new IdRef(ref));
def acp = doc.getACP();
def result = null;
if (aclname != null) {
def acl = acp.getACL(aclname);
if (acl == null) {
result = "No Such ACL: ${aclname}. Available ACLS: ";
for (a in acp.getACLs()) {
result+=a.getName()+" ";
return result;
result = "{bold}${aclname}{bold}n";
for (ace in acl) {
result += "t${ace}n";
} else {
result = "";
for (acl in acp.getACLs()) {
result += "{bold}${}{bold}n";
for (ace in acl) {
result += "t${ace}n";

return result;

And here is the MVEL example:

org.nuxeo.ecm.core.api.Blob myBlob=Document.getProperty("file:content");
Context["filename"] = myBlob.getFilename();
String[] splitedFilename=Context["filename"].split(".");
if (splitedFilename.length>=2){

The different variables available in Nuxeo are explained on the wiki. If you already know NuxeoStudio, it's exactly the same.

Pretty cool, huh?

Now batch that script!

Some of the scripts we do sometimes need to be ran at a particular time. So instead of using the shell in an interactive mode, we use the batch mode. There are three different batch modes:

  1. Run commands from a file
  2. Run commands from standard input
  3. Run commands specified on the command line - this is a convenient way to run a short list of commands

Here's how you do it:

java -cp nuxeo-shell.jar -f my_batch_file

my_batch_file contains the different commands you need to run. Here's a sample from the documentation:

# connect to local server using the Administrator account.
connect -u Administrator -p Administrator http://localhost:8080/nuxeo/site/automation

# we are now in the repository root. Go to /default-domain/workspaces
cd /default-domain/workspaces

# list the content of the workspaces root - as document UIDs
ls -uid

You'll find examples for the two other modes on the wiki. Now you can use cron to execute your script at any time you want :)

Still not enough? Extend the shell.

If you have enjoyed what you read, and want to dive further in the shell, you need to read the Extending the Shell page on the wiki. And if you need examples, you can always check out the sources on GitHub. We love pull requests so don't hesitate :)