[texhax] Playing Movies/Executing scripts from pdf files

Steve Schwartz s.schwartz at imperial.ac.uk
Sun Feb 5 16:33:24 CET 2006

Dear All,

Some time ago I posted a query concerning launching a script to run a
movie from a pdf file created by pdflatex (e.g., using beamer to make a
presentation). Here's my original posting:


Many people have written to me asking if I had found a solution, to
which my reply was no. Then Achim Beetz did the same thing and, a couple
of hours later, sent me the (partial) solution from which I put together
the final bits. What follows is how it's done in Linux.

It's all a question of mimetypes that acroread knows how to handle
which, of course, it gets from the system, e.g., /etc/mailcap,
~/.mailcap, etc. In addition (which Achim didn't tell me), you need to
teach your system about the file extensions, in ~/.mime.types, so it can
then go look up the appropriate application.

In your latex source there is, for example:

\href{run:movie_script.sh}{Click Here}

movie_script.sh is just a shell script to run your favorite player, e.g.
a file with the one line:

mplayer -geometry 50%:50% -nofs  /home/sjs/movies/mymovie.mpg

(xine also works pretty well; you need something with a good command
line interface and which gives you control, e.g., to hide the controls,

Then you need:

In ~/.mailcap:
application/x-sh; /bin/sh %s

to invoke sh to run your shell script. You can also use /bin/bash or some 
other shell interpreter. You also need to associate the .sh 
ending with a shellscript:

In ~/.mime.types:
application/x-sh sh

That's it! In putting together the final pieces following Achim's help, I 
ran across postings that discouraged putting application/x-sh
in your .mailcap. I presume this is because your browser will also pick
up this information and if a web-page has a similar href link to a shell
script, it will run it without prompting on your machine! Of course, it
has to first put a suitably evil shellscript somewhere it can find and then
execute it. But I can see the dangers. I guess there might be a way to
modify the acroread script so that only acroread finds this .mailcap
entry. Suggestions from gurus most welcome. Perhaps using your own special
filename ending and only putting that in .mime.types would be sufficient,
or more tediously simply editing/swapping multiple versions of .mailcap

Finally, as Achim pointed out, you can do the same thing directly on the
movie file, by specifying, e.g.,

In ~/.mailcap:
video/*; mplayer [options] %s

You will obviously need to teach .mime.types about suffices for video files.
Then you can run the movie directly:

\href{run:mymovie.mpg}{Click Here}

This is another way to avoid the security risk of opening up /bin/sh, at the
expense of not being able to control the movie geometry, repitition, or
other parameters you might put on the command line. Perhaps these could all
be coerced into the "filename" passes through %s?

Anyway, my thanks to Achim.

Professor Steven J Schwartz      Phone: +44-(0)20-7594-7660
Space and Atmospheric Physics    Fax:   +44-(0)20-7594-7772
The Blackett Laboratory          E-mail: s.schwartz at imperial.ac.uk
Imperial College London          Office: Huxley 6M70 
London SW7 2BW, U.K.             Web: http://www.sp.ph.ic.ac.uk/~sjs

More information about the texhax mailing list