Extending Nautilus: rotating JPG images

Customize the GNOME file manager with scripts

User space | Intermediate

By Scott Carpenter

Online on: 2007-10-06

( Download the files attached with this article)

I recently went looking for a way to rotate JPG images from within Nautilus, and found a nice way to do this and more. It’s not difficult to customize the right-click popup menu in Nautilus to perform custom actions on files. Here are some instructions and scripts to get you started.

I often have vertically oriented camera pictures that I want to rotate from within the file manager. Windows Explorer has a nice feature where you can multi-select pictures in thumbnail mode, right-click to get a popup menu (also known as the context menu), and pick clockwise or counter-clockwise rotation. This is a lossless transformation, as opposed to what you’ll likely get if you open up an image in your favorite graphics program, rotate it, and resave. That method is also cumbersome if you’re like me and just wanting to bulk rotate your images after you pull them in from your camera.

This is one of the many things I’ve been gradually learning while replacing my previous Windows capabilities, and as usually happens when I find a solution in GNU/Linux, I was pleased at the elegant building block approach of *nix systems. I found that I have the power of bash at hand from within Nautilus, with scripts that further take advantage of some nifty utilities I’ll cover below.

I found that I have the power of bash at hand from within Nautilus, with scripts that further take advantage of some nifty utilities

It’s true that many import programs will rotate your images automatically as they are pulled from the camera, but not all of them will, and you won’t always be able to use the importer of your choice. It’s also possible your camera doesn’t store the proper Exif metadata in the image file, leaving your super funky-cool import program helpless. So I think we can all agree that this is something you must have for ease of photo management.

I’ll look specifically at image file operations to demonstrate how Nautilus can be extended. I’ll cover on JPG files which are practically the universal format in digital cameras (at least those used by us common folk) and use Exif data that allows us to do several neat things.

After working through this tutorial, you should be able to right click on your images in Nautilus and have menu options as shown in figure 1.

Figure 1: GNOME Nautilus file manager right click popup menu
Figure 1: GNOME Nautilus file manager right click popup menu

This corresponds to the hierarchy in your home directory:

~/.gnome2/nautilus-scripts/img/
        autorotate.sh
        change-date-and-rename-with-exif.sh
        change-mod-date-to-exif.sh
        rename-with-exif-date.sh
        rotate-left.sh
        rotate-right.sh
        caution/strip-exif.sh

Preliminaries

The public domain code for these scripts appears below. You can also grab downloads.tgz (see the download icon at the beginning of this article) and extract it to your nautilus-scripts directory: ~/.gnome2/nautilus-scripts$ tar -xvf downloads.tgz

The GNOME page for extending Nautilus is a good place to start. It mentions that you can also use the File→Scripts menu to run your scripts, and from either there or the right click context menu, you can select the “Open Scripts Folder” item to open up the directory in Nautilus. If you don’t have any scripts installed, you won’t get these menu options. Make sure the scripts you create are executable.

Possible Gotcha

I initially couldn’t get my scripts menu to appear when I put the scripts in the root of nautilus-scripts, and thought they needed to go in subdirectories. But when I checked again while writing this, it worked fine that way.

Then after removing and restoring files to my preferred hierarchy, I couldn’t get my scripts to appear in the menu again, even after closing and reopening Nautilus. I had to force a reload of the directories in Nautilus to see everything in the menu again, using the little blue circular arrow in the toolbar. Maybe this had something to do with my original problem.

In any case, if things don’t appear as expected, make sure to reload the nautilus-scripts directory. (Also available in menu View→Reload and with keyboard shortcut CTRL + R.)

There is one more thing to do before you start looking at the scripts. You will need the jpegtran utility from the Independent JPEG Group and jhead, by Matthias Wandel. Both are small and robust free software programs. jhead is public domain, and jpegtran has its own license that appears to be fully free.

Tags: gnome, nautilus, pictures, shell scripts

License

(C) Scott Carpenter 2007

This article is made available under the "Attribution-Sharealike" Creative Commons License 2.5 available from http://creativecommons.org/licenses/by-sa/2.5/.Please use this attribution for derivatives and republications: By Scott Carpenter (http://www.movingtofreedom.org), originally published in Free Software Magazine.

Biography

Scott Carpenter: Scott Carpenter has been lurking around the fringe of the free software movement since 1998 and in 2006 started a more concentrated effort to "move to freedom." (Chronicled at the Moving to Freedom blog: http://www.movingtofreedom.org/.) He has worked as a professional software developer/analyst since 1997, currently in enterprise application integration. (Views expressed here and at movingtofreedom.org are strictly his own and do not represent those of his employer. Nor of miscellaneous associates including friends and family. Nor of his dog. It's possible they're representative of his cats' opinions, but unlikely. Void where prohibited. Local sales tax applies.)

Anonymous visitor's picture

You are better off using nautilus-actions

Your advise above uses nautilus-scrips. But they have been succeeded by nautilus actions.

The differences:
- nautilus actions can be configured to apply to certain file types and/or groups of specific file-types or mime-times
- you can specify an icon with the action
- you can export and import the actions
- there exists a graphical interface to manage and configure nautilus-actions

Unfortunately they are heavily under-used. No linux distrobution using nautilus install this by default. Sane default choices would be: converting audio/video/pictures/documents to another format, printing pictures/documents, emailing files, etc. Unfornately some of this stuff is supported through normal nautilus extensions rather than nautilus actions.

Nautilus scripts is deprecated anyway. Please google nautilus-actions.

Scott Carpenter's picture

...

Hi, Anon, and thanks for your comment. I was aware of Nautilus Extensions as a more powerful alternative to scripts. I relied on the GNOME page linked above for some of my information:

http://www.gnome.org/learn/users-guide/latest/gosnautilus-440.html

Reading more carefully in the Extensions section, I see where it mentions nautilus-actions. It doesn't say anything on that page about scripts being deprecated. While I'm sure I'll eventually look more closely at Extensions, I went with scripts as something readily available and the path of less resistance. Still, I should have mentioned it as another option in the article. Thanks for pointing it out.

If nautilus-actions is based on file type, I wonder how it would apply to actions you want to apply to many file types? I have a script that converts spaces in filenames to dashes, and another that sends selected files to the Meld diff viewer.

Lawrence D'Oliveiro's picture

JPEG, not JPG

Just a note that the proper name for the format is "JPEG", not "JPG". The truncated version derives from naming constraints on certain non-Free operating systems. No need to perpetuate those restrictions when you don't have to!

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options


[The Top 10 Everything] [Zoeshire] [FSDaily RSS] [Book Reviews - Illiterarty]