"Open attachment with" macro in mutt email client
Asked Answered
C

2

6

Sometimes I receive email attachments whose mimetypes are not in my mailcap file. To open such attachments from mutt, I usually select the attachment from the list, hit s to save the file to /tmp, and then use ! to open the saved file with whatever application suits, using a shell command.

Is it possible to automate this with a mutt macro, which simply saves the selected attachment to /tmp, queries for an application name, and then opens the saved file with this application?

Clean answered 4/2, 2014 at 22:28 Comment(0)
C
11

I will answer my own question. The following entry in .muttrc does what I want:

macro attach O \
"\
<enter-command>unset wait_key<enter>\
<shell-escape>rm -f /tmp/mutt-attach<enter>\
<save-entry><kill-line>/tmp/mutt-attach<enter>\
<shell-escape> /tmp/mutt-attach &^A\
"

Description (line by line):

  • map the macro to the O key in attachment mode
  • disable "Press any key to continue ..."
  • remove the file /tmp/mutt-attach if it exists
  • save the selected entry to /tmp/mutt-attach
  • start a shell command, input /tmp/mutt-attach & and go to the beginning of the line (^A)

Then I can simply input the program I want to use and hit enter, which will open the selected attachment in the background.

Clean answered 5/2, 2014 at 0:12 Comment(0)
E
0

Or if you want to always open the same program (firefox in my case):

macro attach F \
"\
<enter-command>unset wait_key<enter>\
<shell-escape>rm -f /tmp/mutt-attach<enter>\
<save-entry><kill-line>/tmp/mutt-attach<enter>\
<shell-escape>firefox /tmp/mutt-attach &<enter>\
"
Edmond answered 12/12, 2016 at 15:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.