Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have most of my home directory dot files shared across my home and work systems, each running a different version of Ubuntu.

I'm looking for a way to specify the default image viewer for each system in ~/.mailcap, so when it's invoked by mutt, the correct image viewer will start.

My current work-around is to put the following in ~/.mailcap ...

image/*; viewimage %s; test=test -n "$DISPLAY";

... where viewimage is a simple bash script:


if [ $hostname == 'work-host' ]; then
elif [ $hostname == 'home-host' ]; then

$imageviewer $1

Any suggestions to avoid this workaround are appreciated.

share|improve this question
the problem with xdg-open is that it launches the relevant application and exit immediately. When xdg-open will exit, the mail reader will then consider that the job is done and remove the attachement that was stored for viewing (most of the time in /tmp) and that before the real viewer was launched. The viewer will then say that it can't find the file to be viewed. – user166931 Jun 13 '13 at 15:02

Your solution is nice and lets you keep all the dotfiles on version control, so why change it? :-)

If you run either of the major desktop environments, invoke xdg-open instead? Is is the equivalent of double clicking a file in the file browser.

share|improve this answer

Your Answer


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.