Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I recently found out that Nautilus (Ubuntu 12.04 at least) can show thumbnails of files of non-image formats, for example (data grapher) grace files (.agr) shows a small version of the graph contained in its data. Obviously, there some library or script that is processing the file, making the image, and allowing nautilus to show a small version of it.

This made me think that in principle any file that potentially can be processed into an image can serve as a Nautilus thumbnail.

For example, a .tex file (which can be converted to .pdf) or a gnuplot script can be displayed as a thumbnail when possible.

In the case of .tex file, the correspoding .pdf can be created by the command pdflatex file.tex.

The question is, how can I tell Nautilus to create a thumbnail for an arbitrary format and how do I specify the commands to do so within Nautilus?


Update 2014,

I still didn't manage to preview anything with the answer posted, I created this script in /usr/bin/tex-thumbnailer:

pdflatex $1
convert -density 300 ${1%.*}.pdf -resize 25% $2

and a file /usr/share/thumbnailers/tex.thumbnailer:

[Thumbnailer Entry]
TryExec=tex-thumbnailer
Exec=tex-thumbnailer %u %o
MimeType=text/x-tex;

I can't make nautilus to generate/show the preview even for simple TeX files. I don't know what I am doing wrong.

share|improve this question
add comment

1 Answer 1

Here's the documentation on how to add a new thumbnailer.

You need to add two keys on gconf:

  • /desktop/gnome/thumbnailers/application@x-foo/enable (boolean)
  • /desktop/gnome/thumbnailers/application@x-foo/command (string)

Where application@x-foo is the MimeType for the kind of file you want to generate the thumbnails. Set enable to True and command to the command to create the thumbnail.

To add one with gconftool-2:

gconftool-2 --set /desktop/gnome/thumbnailers/application@x-foo/enable --type bool true
gconftool-2 --set /desktop/gnome/thumbnailers/application@x-foo/command --type string "application-x-foo-thumbnailer %i %o %s"

The folders are created automatically. %i is the input file, %o where to write the output file (png) and %s the size of the thumbnail.

And here's how to add a MimeType for custom files.


I found another way which seems easier, you can create a file in /usr/share/thumbnailers/ for example foo.thumbnailer:

[Thumbnailer Entry]
TryExec=/usr/bin/application-x-foo-thumbnailer
Exec=/usr/bin/application-x-foo-thumbnailer %i %o %s
MimeType=application/x-foo;

You can separate several MimeTypes with ;.

share|improve this answer
    
thanks, how do I exactly create the "folder" application@x-foo inside /desktop/gnome/thumbnailers?, when I right click I only get "New Key..." (other options, grayed out) (Ubuntu 12.04, gconf-editor 3.0.1, both as root or as user) –  alfC Jun 30 '12 at 5:02
    
thank you, for the detailed answer. First, for the files I want the reported type is "text/x-tex", therefore I added the keys in: /desktop/gnome/thumbnailers/text@x-tex/. Second the conversion requires two steps .tex->.pdf->.png, so I use this as the composite command "pdflatex %i && convert basename %i .tex.pdf %o". After restarting, still doesn't work. maybe it is the fact that this is a "text-" file and not an "application-" file. Or maybe the parser gets confused by the composite command. I'll mark this as the accepted answer but any help is still appreciated. –  alfC Jun 30 '12 at 19:21
    
Probably the later, you could try creating a bash script with all the steps inside so it's just one command. –  solarc Jul 1 '12 at 21:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.