Behind the curtain.. Nemo actions
by clem 28

One of the really cool things in Nemo 1.8 is the fact that system administrators and application developers can extend its functionality and integrate their tool with it. Let’s take mintStick, aka the “USB Image Writer” as an example.

The way you used mintStick in Linux Mint 14 was by:

  • Clicking Menu->Accessories->USB Image Writer
  • Clicking the empty ISO field and browsing for an ISO image
  • Selecting your USB stick
  • Clicking on the button..

Usually, you’d do that right after you downloaded the ISO… with Nemo showing you that ISO file right in front of you..

With Nemo 1.8, things are a little bit different. MintStick provides a Nemo action for ISO files and what this means is that you can basically right-click the ISO file and select “Make bootable USB stick”. This launches mintStick of course … with the ISO field pre-populated. All you have to do then is to select your USB device and click on the button :)

By providing this action, mintStick integrates itself closely with Nemo and makes it easier for you to do things.

If you wanted to do this in Nautilus or Nemo 1.6 you would need to program in C and write an “Extension”, which you would then compile and whatnot… this is tedious and it’s not what we had in mind for Nemo. So instead, we made Nemo understand actions, the way your menu understand menu items. An action is nothing else than a text file which tells Nemo what to do.

Here’s /usr/share/nemo/actions/mintstick.nemo_action:

[Nemo Action]
Active=true
Name=Make bootable USB stick
Comment=Make a bootable USB stick
Name[fr]=Créer une clef USB bootable
Comment[fr]=Créer une clef USB bootable
Name[nl]=Maak uw eigen opstart-USB stick
Comment[nl]=Maak uw eigen opstart-USB stick
Name[de]=”Einen bootfähigen USB-Stick erstellen”
Comment[de]=”Einen bootfähigen USB-Stick erstellen”
Exec=mintstick %F
Icon-Name=gtk-execute
Selection=S
Extensions=iso;img;

As you can see, it’s quite straight-forward… it adds an action called “Make bootable USB stick” to your context menu whenever you right click on an “iso” or “img” file, and it launches “mintstick” with the name of that file when you click on it.

Just a single text file, and our mintStick is now much easier to use ;)

28 thoughts on “Behind the curtain.. Nemo actions

  1. Reply clem May 4, 2013 20:25

    PS for MATE users: We talked to the MATE devs about it and they liked the idea. We shared the code for it and it’s likely to happen in Caja 1.8 (Mint 16).

    • Reply Kirk M May 5, 2013 01:15

      Clem – I’m not sure what’s wrong but whenever I’ve used the USB Image Writer (both the new version in Mint and the older version that was included in older versions of Ubuntu) it pretty much wiped out any thumb drive it’s attempted to write to–3 so far. Two I’ve managed to recover and one I couldn’t recover at all. The computer won’t even recognize them at all after the USB Image Writer gets done with them.

      All thumb drives are formatted FAT32 for compatibility with both Linux distros and Windows (7) and all thumb drives work fine with Unetbootin for writing both 32 and 64 bit (hybrid) distros (and I’ve written distro after distro to both CD\DVD and thumb drives over the years).

      There’s nothing unusual about either my desktop PC (Gateway Intel Core 2 Quad) or Laptop (ThinkPad R61) yet I have the same problem using the USB Image Writer with both machines on my thumb drives.

      Not complaining, just mentioning.

      • Reply clem May 5, 2013 08:28

        Hi,

        These tools dd into your device. As a result, your FAT32 partition is gone and all the data on it. Of course the disk is still usable, but you need to repartition it and reformat it to FAT32 if you want to use it to store data again.

      • Reply bobby May 6, 2013 15:29

        Hello Kirk : I also faced the same problme. My windows7 and linux were not reading the USB after using the image writer. Simple solution is use gparted. While using gparted be extra careful to select the appropriate USB drive only. First unmount by right clicking, if it shows some lock like small icon, then delete all the partitions in USB and then in the end format it to fat32. It will be usable again. Aahhhh to whom I am telling all this, Kirk, just mentioning of Gparted is enough for you or Clem mentioning of partion tool.

        • Reply Kirk M May 6, 2013 23:40

          Clem and Bobby – I did forget to mention that none of the thumb drives that were written to by USB Image Writer would boot either. Something about not being able to find the kernel. Doesn’t matter since Unetbootin doesn’t wipe out the FAT32 format of the thumb drive. I often back up the home directory of whatever computer I’m upgrading to the same (8GB) thumb drive (say from Mint 14 to Mint 15 for example?) after Unetbootin “burns” the .iso to it.

          No big deal like I said.

  2. Reply Vivek May 4, 2013 23:30

    great to see.. I would like to move my work environment into cinnamon

  3. Reply xenopeek May 5, 2013 06:53

    Besides matching on extensions, are there other selectors you can use in Nemo actions? For example, if you want to make a Nemo action for directories.

    And, perhaps a premature question, but if Caja includes code for this would it also use the /usr/share/nemo/actions/mintstick.nemo_action file, with the [Nemo Action] header, or would it have its own path and header for action files?

    • Reply clem May 5, 2013 08:26

      Yes, you can have the action apply to directories or other kinds of selections (multiple files, no selection at all..etc..).

      Regarding Caja, I’m not sure. I guess it would be the same syntax but using a different path.

  4. Reply Mark Walton May 5, 2013 10:15

    Guys,

    Just to echo the comments above; more excellent work from Clem and the dev team.
    I’m eagerly awaiting the next release and new functionality.
    Keep up the great work :)

    Mark

  5. Reply T_U May 5, 2013 10:20

    Excuse-me if I’m wrong, but isn’t it sth that is already implemented under KDE ? Wouldn’t it be possible to cooperate with KDE / share a common specification ?

    • Reply clem May 5, 2013 11:39

      Yes. Dolphin supports the same concept via something called ServiceMenu. It’s something we use in Mint KDE already and it works pretty well: http://packages.linuxmint.com/pool/main/r/rootactions-servicemenu/

      I wanted to see that in Nemo for Mint 15 personally. I thought the idea came from XDG and .desktop files in /usr/share/applications, and that’s what I used to describe the design when we started implementing it. I forgot about KDE ServiceMenus to be honest, but it probably played a role and gave us some inspiration.

      Looking at their format, it’s very similar, here’s an example:

      [Desktop Entry]
      Type=Service
      ServiceTypes=KonqPopupMenu/Plugin,text/*,application/x-desktop
      Actions=Editassu

      [Desktop Action Editassu]
      Name=Edit as Root
      Name[it]=Edita come Root
      Name[fr]=Editer en tant que Root
      Name[es]=Editar como Root
      Name[de]=Als root bearbeiten
      Icon=kfm
      Exec=kdesu “kwrite” “%U”

      The path and format used by Dolphin/Nemo/Caja/Thunar could be standardized to make it easier for developers to create generic actions which work in all DEs I guess. As long as the action could define which DE it applies to and that the format wouldn’t restrict us when it comes to implement specific features, I’d be all for it and I’d support its implementation. That’s a discussion we should have with the other teams or which should be picked up by XDG.

      In terms of cooperation, we’re very close to the MATE devs (I’m part of the MATE team myself) so we already talked about this with them. I’ll get in touch with the Kubuntu guys (I’ve very little contacts within the KDE team) and leave the door open for everyone else to get in touch with us.

      • Reply T_U May 5, 2013 13:01

        Thanks for the reply Clem ! That’s nice to hear you care for cooperation.

        (BTW, I’m sure Dolphin could be an interesting source of inspiration for Nemo, it has many neat features)

  6. Reply dRaiser May 5, 2013 21:10

    It’s working greated. I’ve create simple script for QNapi – subtitles downloader. Please enjoy: https://gist.github.com/dRaiser/5522425

    • Reply mtwebster May 5, 2013 23:55

      You can use ~/.local/share/nemo/actions directory instead of putting in /usr/share/nemo/actions as well.

  7. Reply dRaiser May 6, 2013 09:35

    Thanks mtwebster, I’ve updated code.

  8. Reply Xanan May 7, 2013 07:35

    Hi Clem,

    Please accept my thanks for making the best Linux distro for an everyday user. I switched over to Linux Mint ever since Ubuntu started throwing Amazon in my face every time I tried to search for something, and I have simply been amazed by what I saw.

    Nemo is a pretty good file manager and I couldn’t ask for more. I do feel that there is still some features that can be added to it to make it even better.

    Also, I was wondering if you can code in a button/slider to increase the icon size in folder view- I normally sit quite a distance away from the screen and the icons and text are too small to be visible. Of course, I can always increase the icon size from the preferences, but having a button/slider similiar to what KDE/Windows 7 has seems to be an added convenience.

    The second thing I would suggest is to have the option of mounting an iso file directly from the context menu- The new ‘actions’ feature of Nemo might accomplish this. Unfortunately, I don’t know any thing about Linux commands or syntax, nor how it is supposed to work, but I guess it shouldn’t be too difficult to implement.

    Another little feature i would suggest is to have the option of shutdown/restart on the desktop right click menu. It is a very convenient option to have, and saves at least a click.

    I also want to make themes and icons for Linux Mint but I do not know where to begin- is there a tutorial some where? I’m good at photoshop etc but lack any programming knowledge. I’m also designing a new look for the Software manager as I feel it can be improved aesthetically. Could you also tell me what would I need to do in order to submit the design so that it can be implemented if found suitable?

    Thanks and regards,
    Xanan

    • Reply clem May 7, 2013 19:38

      Hi Xanan,

      Come and meet us on IRC. We’re at irc.spotchat.org (#linuxmint-dev). It would be hard to maintain more than one theme. We’re focused on Mint-X but we would appreciate any help in improving it. If you’re skilled in Web design, the Software Manager, the Welcome Screen and the Login Screen all use HTML in their interface and we’re definitely interested in new designs there.

    • Reply mtwebster May 7, 2013 19:52

      Xanan, there is already a slider you can use to zoom in/out of the view (in addition to Ctrl-Mousewheel): If it’s not already on, the status bar has a zoom slider. You can turn it on by going into the View menu and toggling Statusbar.

      You should already be able to (at least in Mint 14) mount an iso directly from the context menu, Open with Archive Mounter.

  9. Reply Mani May 23, 2013 17:31

    I hope you can help me with a little question:
    I wanted to create a converter action which should convert
    img and nrg to iso. To do this i used the commandline tool “iat”,
    the Syntax in the Terminal would be:

    iat /Path/To/Image.nrg /Path/To/Image.iso

    Now i have a little Problem:
    I don’t know how to make the Output path the same as the input path
    (i want to have the convertet iso in the same folder as the original)
    So it would be:

    Exec=iat %F …

    But i have no clue what … has to be

    • Reply VolMi May 27, 2013 15:41

      You can put whatever functionality in an external script and just call that script from the nemo action. I like shell scripting, so I created one for your problem:
      https://gist.github.com/VolMi/5658061

      If you save it as ~/bin/iatconvert, your command for the nemo action becomes

      Exec=iatconvert %F

      Don’t forget to make the shell script executable:
      chmod +x ~/bin/iatconvert

  10. Reply Tony May 25, 2013 21:12

    Nemo-actions is a nice move. I like to be able to directly edit certain sorts of files. Here’s an action that does it for .txt, .sh,.conf,.log and .list files – obviously you can add other file extensions as preferred.

    [Nemo Action]
    Active=true
    Name=Edit file as Root
    Comment=Open with gEdit as root
    Exec=gksudo gedit %F
    Icon-Name=accessories-text-editor
    Selection=S
    Extensions=txt;log;sh;conf;list;

  11. Reply rtimai Jul 20, 2013 01:49

    Great information on Nemo here!

    I modified the sample nemo_action file and successfully added ‘Extract here’ to my Nemo actions. I didn’t know what to use for Icon-Name= or Stock-Id= so I left those entries commented-out (file-roller?) And the action works as before in Nautilus, including appearing only when archive files are selected.

    File:
    /usr/share/nemo/actions/extract_here.nemo_actions/
    -or-
    /.local/share/nemo/actions/

    [Nemo Action]
    # Use this entry for troubleshooting
    # Lack of this field assumes true
    #Active=false

    # The entry name to show in the context menu, locale supported with standard desktop spec
    # Use %N as an (optional) token to display the simple filename in the label
    # If multiple are selected, then the arbitrary first selected name will be used
    # Token is inactive for selection type of Multiple, None and Any (it will be treated literally)
    # **** REQUIRED ****
    Name=Extract here

    # Tool tip, locale supported (Appears in the status bar)
    # %N can be used as with the Name field, same rules apply
    Comment=Extract archive here

    # Application to run. Enclose in to run an executable that resides in the actions folder
    # Use %U as a token where to insert a URL list, use %F as a token to insert a file list
    # **** REQUIRED ****
    #Exec=gedit %F
    Exec=file-roller -h %F

    # Icon name to use in the menu - must be a theme icon name
    #Icon-Name=file-roller

    # Gtk Stock ID to use for the icon. Note if both Icon-name and Stock-Id are
    # defined, the Stock-Id takes precedence.
    #Stock-Id=file-roller

    # What type selection: [S]ingle, [M]ultiple, Any, or None (background click)
    # Defaults to Single if this field is missing
    Selection=Any

    # What extensions to display on - this is an array, end with a semicolon
    # Use "dir" for directory selection and "none" for no extension
    # Use "any" by itself, or semi-colon-separated, for any .-type
    # Extensions are NOT case sensitive. jpg will match JPG, jPg, jpg, etc..
    # **** REQUIRED ****
    #Extensions=any;
    Extensions=.7z;.ar;.cbr;.cbz;.cpio;.exe;.iso;.jar;.rar;.tar;.tar.7z;.tar.Z;.tar.bz2;.tar.gz;.tar.lz;.tar.lzma;.zip;

    Not for rank newcomers, and YMMV, of course. If anyone writes a more elegant version please share!,

    Oh btw, I’m running Ubuntu 13.04 Unity, with Nemo installed from the Ubuntu Software Center (doing so does not install Cinnamon,) and Nemo works great. I NEED Tree View in the sidebar!

    Also, fanDigital provided useful information for integrating Nemo with the Unity desktop (without removing Nautilus):

  12. Reply Nemes Sorin Aug 22, 2013 23:30

    A simple question here …

    Nautilus Actions was a very good tool – Can Nautilus Actions be used as a model of a future Nemo Action Tool ?

  13. Reply Pekka Niemi Dec 2, 2013 14:40

    Dear Clem,

    there is one teeny-weeny issue with actions. When using %F parameter, spaces in the filenames break the command line arguments. Sure, this could be handled by using quotation marks, but then handling several filenames is impossible. Am I missing something here?

    Best regards,

    Pekka

    • Reply Samuel Dec 19, 2013 15:09

      I’ve been able to get around this by taking advantage of the fact that Nemo will pass your script absolute paths. When operating on multiple files, I use %F (no quotes) in the .nemo_action file. In my script, I paste together arguments to form complete filenames. Since absolute paths are used, you can find the end of one filename and the beginning of the next by looking for arguments that start with the “/” character.

      Take the following sample code:

      IFS=$(echo -en “\t”)
      ary=($(echo -n “$@” | sed -e ‘s: /:\t/:g’))
      for this_file in “${ary[@]}”; do
      # Do something to the file
      done

      This converts all ” /” sequences into “/”, which leaves us with a tab-separated list of file names. Setting IFS to tab (instead of the default “any whitespace”) causes the second line to create an array by splitting the string at the tabs. The end result is “ary” being an array of complete filenames, spaces and all, which can be iterated through. Just remember to quote the individual filenames when you reference them!

      Yes, this is an ugly hack and will likely break on certain unusual names (like a folder with a space at the end of the name), but it’s the best I’ve been able to come up with so far. The only *real* way to solve this is for Nemo to add an option that will pass the script a list of individually-quoted filenames (like ["/path/to/file 1.txt" "/path/to/file 2.txt"].

    • Reply Bob Good Mar 26, 2014 02:28

      Hi,

      [Nemo Action]
      Name=Open with gedit
      Comment=Open text file with gedit

      Exec=/home/user/.scripts/Gedit %F

      Icon-Name=gedit

      Selection=s

      Extensions=any;

      *

      Gedit bash script…
      Name this script Gedit, and, in my case, I placed it in a hidden folder named ~/.scripts (I have a bunch of other self made scripts that I run from there). Make Gedit script executable.

      #!/bin/bash

      textfile=echo "$@" | sed 's/ /\?/g'
      gedit $textfile

      exit 0

      *
      This little script will open text files with spaces in its name/title.

      Later…

      Bob

      • Reply Bob Good Mar 26, 2014 02:34

        #!/bin/bash

        textfile=echo "$@" | sed 's/ /\?/g'
        gedit $textfile

        exit 0

        • Reply Bob Good Mar 26, 2014 02:41

          [Code]
          #!/bin/bash

          textfile=echo "$@" | sed 's/ /\?/g'
          gedit $textfile

          exit 0
          [/Code]
          Site is leaving out the grave accent symbols from the echo/sed section. Sorry.

Leave a Reply