Le but de la manip est d'
attacher des fichiers à un mail Thunderbird par clic droit dans Konqueror. Le script propose en plus le
redimensionnement automatique des images s'il y en a, et une
barre de progression pour suivre l'avancement des opérations.
Installation :
1.
Vérifier que imagemagick est installé :
sudo apt-get -y install imagemagick
2.
Créer l'item du menu :
Editer le fichier email.desktop de la façon suivante :
kate ~/.kde/share/apps/konqueror/servicemenus/email.desktop
puis coller ce contenu
[Desktop Entry]
ServiceTypes=all/allfiles
Actions=attach
[Desktop Action attach]
Name=Email ...
Name[fr]=Envoyer par mail ...
Icon=thunderbird
Exec=~/bin/ktbmail %U
Sauver le fichier.
3.
Créer le script :
mkdir ~/bin
cd ~/bin
touch ktbmail
chmod +x ktbmail
kate ktbmail
puis y coller le contenu suivant :
#!/bin/bash
# Author : Eddy
# Date : 2006/07/13
#
# thunderbird version >= 1.5 and imagemagick packages must be installed
#
# Default language = English
_warning_title="Warning"
_warning_text="Please select at least one file !"
_progress_title="Preparing"
_progress_first_text="Processing ..."
_progress_text="Processing file"
_prompt_title="Scale image(s) ..."
_prompt_text="Choose the desired definition :"
_prompt_column_title="Size"
_def_unchanged="Original definition"
case $LANG in
# If language = French
fr* )
_warning_title="Attention"
_warning_text="Il faut sélectionner au moins un fichier !"
_progress_title="Préparation"
_progress_first_text="Traitement en cours ..."
_progress_text="Traitement du fichier"
_prompt_title="Redimensionner l'(es) image(s) ..."
_prompt_text="Choisir une définition maximum ci-dessous :"
_prompt_column_title="Taille"
_def_unchanged="Définition originale"
esac
# First make sure there's something selected (should be the case ...)
if [ $# -eq 0 ]; then
kdialog --sorry "$_warning_text" --title="$_warning_title"
exit
fi
# Store the number of files to process.
NB_FILES=$#
# Reset the attachment list.
echo "" > /tmp/attachment.log
# Launch the progress dialog box
PROGRESS=`kdialog --progressbar "$_progress_first_text" $NB_FILES`
dcop $PROGRESS showCancelButton true
dcop $PROGRESS setAutoClose true
# Here we go
while [ $# -gt 0 ];
do
# Store the file name and uri.
FILE="$1"
FILE_NAME=`echo "$FILE" | awk -F "/" '{print $NF}'`
FILE_URI=file://"$FILE"
# Update the progress dialog
let "COMPTEUR += 1"
dcop $PROGRESS setLabel "$_progress_text $FILE_NAME ($COMPTEUR/$NB_FILES) ..."
if [ "true" == `dcop "$PROGRESS" wasCancelled` ]; then
dcop $PROGRESS close
exit
fi
# Test if the file is a picture.
# The following line may not work if the file is on the desktop ...
# IS_IMAGE=`file -bi "$FILE_NAME" | grep -c image`
# so we do differently.
# Note that we reduce only jpeg files.
# If we wanted to reduce other types of picture file then we could do something like that :
# IS_IMAGE=`echo $FILE_NAME | grep -c -E [.]jpg\|[.]gif\|[.]png`
IS_IMAGE=`echo "$FILE_NAME" | grep -c -E [.]jpg\|[.]JPG\|[.]jpeg\|[.]JPEG`
if [ $IS_IMAGE != 0 ]; then
# If the file is an image, prompt for reducing it.
if [ ! $DEF_ASKED ]; then
DEF=`kdialog --radiolist "$_prompt_text" unchanged "$_def_unchanged" off 1280x1280 1280x1024 off 1024x1024 1024x768 on 800x800 800x600 off 640x640 640x480 off --title "$_prompt_title"`
if [ $? = 1 ]; then
dcop $PROGRESS close
exit
fi
DEF_ASKED=1
fi
# Test if there is a resize to do
if [ "$DEF" != "unchanged" ]; then
# Do the resize
convert "$FILE" -scale $DEF "$HOME/.local/share/Trash/files/$FILE_NAME"
# Store the reduced file uri in place of the file uri.
FILE_URI="file://$HOME/.local/share/Trash/files/$FILE_NAME"
fi
fi
# Add the file uri to the attachment list.
if [ "$ATTACHMENT" == "" ]; then
ATTACHMENT=$FILE_URI
else
ATTACHMENT=$ATTACHMENT,$FILE_URI
fi
# And continue with the next file ...
dcop $PROGRESS setProgress $COMPTEUR
shift
done
# Make the attachment
mozilla-thunderbird -compose "attachment='$ATTACHMENT'"
Sauver le fichier.
4.
Faire un essai !
Si ce post vous a été utile, n'hésitez pas à le dire ça me fera plaisir 😃
(si quelque chose ne marche pas ça me fera moins plaisir mais vous pouvez le dire aussi ...)