Using Nautilus Actions to Extend File Manager Functionality on Linux

8881

 

What would a desktop be without a file manager? Even at the command line level we have file managers and they still make our lives much easier than they would be without them. To many users the file manager is just way to preview, delete, and move files. The power user, on the other hand, looks at the tool from a very different vantage point. For this type of user the file manager must be versatile, powerful, and it must do their bidding in the way they want it done.

The GNOME default file manager, Nautilus, is the perfect candidate for this. How? There is an add on for Nautilus called nautilus-actions. With this tool users are able to add context-sensitive actions to menus that allow programs to be launched based on the file type selected. Say, for example, you want to be able to install downloaded fonts directly (and quickly) from within Nautilus. This is possible. Or say you want to quickly add songs to your Rhythmbox playlist and automatically begin playing them (all from within Nautilus). This too is possible. In fact, Nautilus Actions is only limited to your imagination.

In this tutorial I’ll start you off your long, useful, journey with Nautilus actions. You will learn exactly how to pull off the two actions I described above which should give you all of the groundwork necessary to be able to start creating your own useful Nautilus actions.

What You Need to Install

This is simple. You need to only install the nautilus-actions package. To do this, follow these easy steps:

  1. Open up your Add/Remove Software utility.
  2. Search for “nautilus-actions” (No quotes).
  3. Mark the package nautilus-actions for installation.
  4. Click Apply to install.
  5. Enter your root (or sudo) password when prompted.
  6. When the installation has completed, close the Add/Remove Software utility.

You should now see a new entry in your System > Preferences menu called Nautilus Actions Configuration. This tool is what you use to create actions in Nautilus. Let’s see how this tool works.

Creating an Action: Queuing and Playing Music in Rhythmbox

For the first action let’s set up Nautilus so that you have the ability to select music and automatically add that music to the Rhythmbox play queue AND start playing it right away. Now, this action requires that the music you want to add to the play queue already be imported into Rhythmbox, otherwise the action will not work.

For this action we will be using the command rhythmbox-client. In a moment you will see exactly how this is used.

Nautilus Actions Configuration tool The first step, after you have the Nautilus Actions Configuration window open, is to click on File > New Action. When this new window opens you will see five tabs. Let’s take the configuration of this action one tab at a time.

Configuring an Action

In the Action tab you need to do the following:

  • Check “Display item in selection context menu”.
  • Check “Display item in location context menu”.
  • Enter “Enqueue Music in Rhythmbox” for the Context label.
  • Check “Display item in toolbar”.
  • Enter “Add music to Rhythmbox Play Queue and Play” in the Tooltip area.
  • Select an icon from the drop down.

Now that you’ve finished there, move on to the Command tab and do the following:

Enter /usr/bin/rhythmbox-client in the Path area.

Enter --enqueue %M --play in the Parameters area. Note that the command has double dashes, not em dashes.

In the file names section you will want to enter all of the audio file formats you plan to use in Rhythmbox. This will be in the form *.mp3; *.flacc; *.acc; *.ogg.

Enter audio/* in the Mimetypes section.

In the “Appears if selection contains” section check “Both” and “Appears if selection has multiple files or folders”.

That’s it. Once you have all of that entered you can click File > Save to save the new action. Before you actually give this a try you need to restart Nautilus with the command nautilus -q in order for everything to take effect.

Now, when you go to a directory that contains music files, select the files you want to add to the Rhythmbox play queue and then either right-click one of the files and select “Enqueue music in Rhythmbox and Play” or click the newly created icon in the Nautilus toolbar. Your music should queue and start playing.

Adding Fonts

I chose this action so I can illustrate a completely different way to add an action to Nautilus. With this action we will be importing the configuration into the Nautilus Actions Configuration window and then adding a script to handle the task of importing the fonts.

Before I explain how this is done, download the fontinstaller.schema and the fontinstaller.sh and place them in your ~/Downloads directory. For this to work you do need to have Zenity installed.

Nautilus Import WizardWith those files downloaded, open up the Nautilus Actions Configuration tool and then click Tools > Import Assistant. What you must do is navigate to the ~/Downloads directory, find the fontinstaller.schema file and click Forward in the Wizard. The next window in the wizard (see Figure 2) allows you to manage duplicates.

This window is only necessary if you already have a job with the same ID. The default selection is the safest as it will not import items with the same ID (preventing an overwrite).

After you click Forward you will see a summary of your import where you can click Apply to finish the import job. Once imported click File > Save and you are ready to move on.

The next step in this process is to give the fontinstaller.sh executable permissions with the command chmod u+x fontinstaller.sh. With the correct permissions you now need to copy this file to /usr/local/bin with the command mv ~/Downloads/fontinstaller.sh /usr/local/bin. You will have to do this with administrative permissions so either su to root or use the sudo command to allow this command to work.

After you have this taken care of, restart Nautilus and you are ready to use this action.

Final Thoughts

Nautilus is one of the most flexible file managers you will find. And adding Nautilus Actions takes this file manager to levels of usability most file managers can only dream of. And with Nautilus Actions, you are only limited to your imagination, so you can create actions for just about anything.