Friday, June 8, 2007

Attach files to thunderbird directly from commandline

Install the script ( e.g attach.sh )


#! /bin/bash
#
# Script created by ASID
# Modified by sura
# Attach files to thunderbird

temp=""
count=0
mydir=`pwd`
for i in $*
do
count=$(( $count + 1 ))
if [ $count -eq $# ]
then
temp=${temp}file://${mydir}/${i}
else
temp=${temp}file://${mydir}/${i},
fi
done

echo $temp

if thunderbird -remote "ping()" 2> /dev/null ;
then
thunderbird -remote "xfeDoCommand(composeMessage,attachment='$temp')"
else
thunderbird --compose "attachment='$temp'"
fi





Then just issue the command

bash attachs.sh filenames

2 comments:

tokland said...

The proposed solution seems to be too verbose, and it does not work if attached files are not in the current directory. That's what I use:

FILES=$(for FILE in "$@"; do
echo "file://$(readlink -f $FILE)"
done | xargs | sed "s/ /,/g")
exec thunderbird -compose "attachment='$FILES'"

Serf said...

@tokland: Nice, but it will not work when the attached filenames or their respective pathnames contain spaces. The adapted script below does.

#!/bin/sh
FILES=$(for FILE in "$@"; do
echo "file://"$(readlink -f "$FILE")""
done | xargs | sed "s/ file:\/\//,file:\/\//g")
exec thunderbird -compose "attachment='$FILES'"