How to add space to Exec path in a Thumbnailer description?

I wish to use mplayer to generate thumbnails for nautilus, so I wrote a perl script as the thumbnailer named "gnome_thumbnailer_with_mplayer", and wrote a description in /usr/share/thumbnailers to tell the system to find the thumbnailer.

At the beginning, the description is:

[Thumbnailer Entry]
TryExec=/home/allfox/programs/gnome_thumbnailer_with_mplayer
Exec=/home/allfox/programs/gnome_thumbnailer_with_mplayer %u %o %s
MimeType=application/vnd.rn-realmedia;application/mxf;application/ogg;application/ram;application/sdp;application/vnd.ms-wpl;application/x-extension-m4a;application/x-extension-mp4;application/x-flash-video;application/x-matroska;application/x-netshow-channel;application/x-ogg;application/x-quicktimeplayer;application/x-shorten;image/vnd.rn-realpix;image/x-pict;misc/ultravox;text/x-google-video-pointer;video/3gpp;video/dv;video/fli;video/flv;video/mp2t;video/mp4;video/mp4v-es;video/mpeg;video/msvideo;video/ogg;video/quicktime;video/vivo;video/vnd.divx;video/vnd.rn-realvideo;video/vnd.vivo;video/webm;video/x-anim;video/x-avi;video/x-flc;video/x-fli;video/x-flic;video/x-flv;video/x-m4v;video/x-matroska;video/x-mpeg;video/x-ms-asf;video/x-ms-asx;video/x-msvideo;video/x-ms-wm;video/x-ms-wmv;video/x-ms-wmx;video/x-ms-wvx;video/x-nsv;video/x-ogm+ogg;video/x-theora+ogg;video/x-totem-stream;audio/x-pn-realaudio;audio/3gpp;audio/ac3;audio/AMR;audio/AMR-WB;audio/basic;audio/midi;audio/mp2;audio/mp4;audio/mpeg;audio/ogg;audio/prs.sid;audio/vnd.rn-realaudio;audio/x-aiff;audio/x-ape;audio/x-flac;audio/x-gsm;audio/x-it;audio/x-m4a;audio/x-matroska;audio/x-mod;audio/x-mp3;audio/x-mpeg;audio/x-ms-asf;audio/x-ms-asx;audio/x-ms-wax;audio/x-ms-wma;audio/x-musepack;audio/x-pn-aiff;audio/x-pn-au;audio/x-pn-wav;audio/x-pn-windows-acm;audio/x-realaudio;audio/x-real-audio;audio/x-sbc;audio/x-speex;audio/x-tta;audio/x-wav;audio/x-wavpack;audio/x-vorbis;audio/x-vorbis+ogg;audio/x-xm;application/x-flac;

Everything works. But later I realized that I can sync this kind of little script to Ubuntu One, so I moved the thumbnailer(named "gnome_thumbnailer_with_mplayer", not the description) to ~/Ubuntu One. Then I changed the description to:

[Thumbnailer Entry]
TryExec=/home/allfox/Ubuntu\ One/fun_goods/thumbnailer/gnome_thumbnailer_with_mplayer
Exec=/home/allfox/Ubuntu\ One/fun_goods/thumbnailer/gnome_thumbnailer_with_mplayer %u %o %s
MimeType=application/vnd.rn-realmedia;application/mxf;application/ogg;application/ram;application/sdp;application/vnd.ms-wpl;application/x-extension-m4a;application/x-extension-mp4;application/x-flash-video;application/x-matroska;application/x-netshow-channel;application/x-ogg;application/x-quicktimeplayer;application/x-shorten;image/vnd.rn-realpix;image/x-pict;misc/ultravox;text/x-google-video-pointer;video/3gpp;video/dv;video/fli;video/flv;video/mp2t;video/mp4;video/mp4v-es;video/mpeg;video/msvideo;video/ogg;video/quicktime;video/vivo;video/vnd.divx;video/vnd.rn-realvideo;video/vnd.vivo;video/webm;video/x-anim;video/x-avi;video/x-flc;video/x-fli;video/x-flic;video/x-flv;video/x-m4v;video/x-matroska;video/x-mpeg;video/x-ms-asf;video/x-ms-asx;video/x-msvideo;video/x-ms-wm;video/x-ms-wmv;video/x-ms-wmx;video/x-ms-wvx;video/x-nsv;video/x-ogm+ogg;video/x-theora+ogg;video/x-totem-stream;audio/x-pn-realaudio;audio/3gpp;audio/ac3;audio/AMR;audio/AMR-WB;audio/basic;audio/midi;audio/mp2;audio/mp4;audio/mpeg;audio/ogg;audio/prs.sid;audio/vnd.rn-realaudio;audio/x-aiff;audio/x-ape;audio/x-flac;audio/x-gsm;audio/x-it;audio/x-m4a;audio/x-matroska;audio/x-mod;audio/x-mp3;audio/x-mpeg;audio/x-ms-asf;audio/x-ms-asx;audio/x-ms-wax;audio/x-ms-wma;audio/x-musepack;audio/x-pn-aiff;audio/x-pn-au;audio/x-pn-wav;audio/x-pn-windows-acm;audio/x-realaudio;audio/x-real-audio;audio/x-sbc;audio/x-speex;audio/x-tta;audio/x-wav;audio/x-wavpack;audio/x-vorbis;audio/x-vorbis+ogg;audio/x-xm;application/x-flac;

But it not works. I just can't get any thumbnail in nautilus. I thought the only change I made is the TryExec and Exec path, and the new path contains a space, this maybe the problem, how can I fix it?

I'm using 12.04 LTS.


For the record, you can also synchronize other folders in your home directory with Ubuntu One, rather than simply copying all the files you want synchronized into ~/Ubuntu One.

Also, you can use quotes in the Exec line (not sure about TryExec). So Exec="/home/allfox/Ubuntu One/fun_goods/thumbnailer/gnome_thumbnailer_with_mplayer" %u %o %s should work. You can try using the quotes in TryExec as well. If the quotes don't work there, you can also probably just remove the TryExec line, and it should work.

Also of note, is that Ubuntu One does not preserve permissions bits, so the executable bit on the script may have been lost, and thus the script would fail to execute as a result.


Thanks for dobey's direction! It is a quoting problem.

I read a document here: https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html

There are two rules: 1-We should use \s to represent space in normal lines; 2-The Exec line is special, if there is space in any part of it, we have to quote that part.

For the TryExec line, it is a normal line, so I should write TryExec=/home/allfox/Ubuntu\sOne/fun_goods/thumbnailer/gnome_thumbnailer_with_mplayer.

For the Exec line, I should write Exec="/home/allfox/Ubuntu One/fun_goods/thumbnailer/gnome_thumbnailer_with_mplayer" %u %o %s.

Now, it is working ;)

Why those specifications do not use the same rule on all lines? It took me so much time to find out the problem >_< .

For anyone need, I also post my thumbnailer here:

#!/usr/bin/env perl
use strict;
use 5.010;

# allfox's GNOME thumbnailer using MPlayer

use File::Temp qw(tempdir);
use List::Util qw(min);
use File::Spec qw();
use URI::Escape qw(uri_unescape);

&thumbnailer(@ARGV);
sub thumbnailer
{
    my($mplayer) = `which mplayer`;
    chomp $mplayer;
    my($input, $output, $size) = @_;
    $input = uri_unescape($input);
    $output = uri_unescape($output);
    if($input =~ /\.part$/i)
    {
        return;
    }
    my $common_arguments = '-nosound -noautosub -really-quiet -noar -noconsolecontrols -nojoystick -nolirc -nomouseinput -nosub';
    my $video_information = `$mplayer -identify -frames 0 $common_arguments '$input'`;
    $video_information =~ /^ID_VIDEO_WIDTH=(?<width>[0-9.]+)
                .*
                ^ID_VIDEO_HEIGHT=(?<height>[0-9.]+)
                .*
                ^ID_LENGTH=(?<length>[0-9.]+)
                /msix;
    my $width = $+{'width'} / 1;
    my $height = $+{'height'} / 1;
    my $length = $+{'length'} / 1;
    if(defined $size)
    {
        if($width > $height)
        {
            my $scale_to = min $width, $size;
            $width = $scale_to;
            $height = $height * ($scale_to / $width);
        }
        else
        {
            my $scale_to = min $height, $size;
            $width = $width * ($scale_to / $height);
            $height = $scale_to;
        }
    }
    my($temp_frames) = tempdir('gnome_thumbnailer_with_mplayer-XXXXXXXXXXXX', TMPDIR => 1, CLEANUP => 1);
    for(1..3)
    {
        $length /= 3;
        if(0 == system "$mplayer -vo jpeg:quality=100:outdir='$temp_frames' -ss $length -frames 1 $common_arguments '$input'")
        {
            last;
        }
    }
    my $convert = `which convert`;
    chomp $convert;
    opendir TEMP_FRAMES, $temp_frames;
    for(readdir TEMP_FRAMES)
    {
        if(/^\d+/)
        {
            my $jpeg_result = File::Spec->catfile($temp_frames, $_);
            system "$convert '$jpeg_result' -thumbnail ${width}x$height png:'$output'";
            last;
        }
    }
    closedir TEMP_FRAMES;
}