如何在Thumbnailer描述中为Exec路径添加空间?

我希望使用mplayer为nautilus生成缩略图,所以我写了一个名为“gnome_thumbnailer_with_mplayer”的缩略图的perl脚本,并在/ usr / share / thumbnailers中写了一个描述,告诉系统找到缩略图。

一开始,描述如下:

[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; 

一切正常。 但后来我意识到我可以将这种小脚本同步到Ubuntu One,所以我将缩略图(名为“gnome_thumbnailer_with_mplayer”,而非描述)移动到〜/ Ubuntu One。 然后我将描述更改为:

 [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; 

但它不起作用。 我在nautilus中无法获得任何缩略图。 我认为我做的唯一改变是TryExec和Exec路径,新路径包含一个空格,这可能是问题,我该如何解决?

我使用的是12.04 LTS。

为了记录,您还可以将主目录中的其他文件夹与Ubuntu One同步,而不是简单地将要同步的所有文件复制到〜/ Ubuntu One中。

此外,您可以在Exec行中使用引号(不确定TryExec)。 所以Exec="/home/allfox/Ubuntu One/fun_goods/thumbnailer/gnome_thumbnailer_with_mplayer" %u %o %s应该可行。 您也可以尝试使用TryExec中的引号。 如果引号在那里不起作用,你也可以删除TryExec行,它应该可以工作。

另外值得注意的是,Ubuntu One不保留权限位,因此脚本上的可执行位可能已丢失,因此脚本将无法执行。

感谢dobey的方向! 这是一个引用问题。

我在这里阅读了一份文件: http : //standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html

有两个规则:1 – 我们应该使用\ s来表示正常行中的空格; 2-Exec系列是特殊的,如果它的任何部分有空间,我们必须引用该部分。

对于TryExec系列,它是一个普通的系列,所以我应该写TryExec=/home/allfox/Ubuntu\sOne/fun_goods/thumbnailer/gnome_thumbnailer_with_mplayer

对于Exec系列,我应该写Exec="/home/allfox/Ubuntu One/fun_goods/thumbnailer/gnome_thumbnailer_with_mplayer" %u %o %s

现在,它正在工作;)

为什么这些规范在所有行上都不使用相同的规则? 我花了很多时间才找出问题> _ <。

对于任何需要的人,我也在这里发布我的缩略图:

 #!/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=(?[0-9.]+) .* ^ID_VIDEO_HEIGHT=(?[0-9.]+) .* ^ID_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; }