LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-06-2015, 12:14 PM   #1
pau
LQ Newbie
 
Registered: Dec 2004
Posts: 4

Rep: Reputation: 0
mailcap syntax to check whether program is available?


Hi:

I am trying to figure out how to tell mailcap that it should check whether a program exists before trying to open the attachment with it.

Something like

Code:
application/pdf; atril %s then use atril, else use evince
In zsh this would be something like this

Code:
        *.pdf|*.ps|*.eps|*.ps.gz|*.eps.gz|*.PDF|*.Ps|*.EPS|*.PS.GZ|*.EPS.GZ)

                         if [ -s $EVINCE ]
                          then $EVINCE $1
                             else
                              if [ -s $ATRIL ]
                              then $ATRIL $1
                                else $XPDF $1
                              fi
                        fi;;
But I do not know how to translate this into mailcap syntax...

Anybody?

thanks
 
Old 11-06-2015, 03:08 PM   #2
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,057

Rep: Reputation: Disabled
In my understanding in the "test=test <something>" construct, "test <something>" could be any test specified by POSIX.

So I would write for instance:
Code:
application/pdf; atril s; test=test -x /usr/bin/atril
application/pdf; evince s; test=test -x /usr/bin/evince
Of course this assumes that these binaries are in /usr/bin, else adapt accordingly.

Caveat: that's what I infer from some docs (mainly "man mailcap") as I never tried that myself.

Last edited by Didier Spaier; 11-06-2015 at 03:34 PM. Reason: Typos fixed and missing word added.
 
Old 11-07-2015, 05:48 AM   #3
pau
LQ Newbie
 
Registered: Dec 2004
Posts: 4

Original Poster
Rep: Reputation: 0
That's not the problem, it suffices with specifying it:

Quote:
`which atril`
But it is not doing what I want, because if it does not find atril, it does not jump to the next possibility. I tried this by writing a wrong name, for instance AAAAAAatril

Quote:
application/pdf; AAAAAAatril s; test=test -x `which atril`
application/pdf; evince %s; test=test -x `which evince`
application/pdf; xpdf %s; test=test -x `which xpdf`
This results in mutt complaining:

Quote:
sh: 1: AAAAAAatril: not found
Press any key to continue...
While I expected it to jump to the next possibility, evince...

For this I need a "if atril does not exist, then use evince, if evince does not exist, then use xpdf"
 
Old 11-09-2015, 12:19 AM   #4
pau
LQ Newbie
 
Registered: Dec 2004
Posts: 4

Original Poster
Rep: Reputation: 0
Ok, I solved this by adding

Quote:
application/pdf; mailcappdf.sh s; copiousoutput
With

Quote:
pyrrha(pts/0)| cat mailcappdf.sh
#!/bin/sh

ATRIL=`which atril`
EVINCE=`which evince`
XPDF=`which xpdf`

if [ -f "$ATRIL" ]
then
$ATRIL $1
else
if [ -f "$EVINCE" ]
then
$EVINCE $1
else
if [ -f "$XPDF" ]
then
$XPDF $1
else
echo "You do not have atril, nor evince, nor xpdf, borinot!"
fi
fi
fi
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Trying to install LibQB, syntax error near unexpected token `CHECK,' hudac Linux - Software 1 06-08-2015 04:56 PM
EMACS - C program syntax error? malxxxl Programming 8 02-23-2013 11:11 PM
[SOLVED] codelite crash, after message Mailcap file /etc/mailcap, line 111.... kaz2100 Linux - Software 1 09-05-2011 07:20 PM
How to check the bash script syntax? mesh2005 Linux - General 2 04-23-2006 08:22 AM
could some check my syntax ehdwuld Linux - Software 1 10-06-2003 12:11 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:12 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration