Skip to content

Aurélien STRIDE

  • Projets personnels
    • Projets Web personnels
    • Language-of.love
    • Squary Movey / Taiketsu-Doku
    • Sudokube / Wordokube / Linkube
    • Recyclage Augmenté
    • Réflexions en 3D
    • Fièvre de cheval du samedi soir
    • Concours divers
  • Dessins
    • 1998 – Arts Appliqués
    • Actualités
    • Compteurs d’eau
    • Divorce
    • Enquêtes
    • GPS
    • Immobilier
    • Informatique
    • Psycho
    • SNCF
    • Vie de couple
    • Dessins divers
  • Musiques
    • 2016 – Oxydoréduction
    • 2012-Maint. – Mashups
    • 2008-2016 – Indaba Remixes
    • 2013 – Live @ Mistral Palace
    • 2012 – Symphonie Electronique
    • 2010 – Metric : Fantasies
    • 2008 – Marcy Playground : Leaving Wonderland
    • 2008-2010 – Ganadji-Nesis
    • 2008-2009 – Mandalas
    • 2007-2009 – Electrons Libres
    • 2006-2007 – Manifest for a generation
    • 2003 – De Inferni Profundis
    • 1997 – MODified
    • Par genre
      • Ambient
      • Jazz
      • Hip-Hop
      • Nightclub
    • Morceaux non classés
    • Vidéos musicales
    • Playlist Soirée Château de Fitou
  • Travaux graphiques
    • Affiches / Flyers
    • Cartes de visite
    • Jaquettes CD-DVD
    • Logos & Bannières
    • Photomontages
    • Sketchups
    • Weavesilk
  • Tutoriels
    • Les outils du dépanneur informatique
    • Liste de mes programmes favoris
    • L’installation idéale d’un OS
    • Installer un serveur web sous Unix
  • Liens favoris
  • Road Trip

Aurélien STRIDE

Life & Works

OS X : traduire ses e-mails depuis Mail

22 octobre 2019 by webmaster

L’application Mail fournie sous MaxOS X ne propose pas de traduction des messages reçus. Cependant un utilisateur propose une solution à partir d’Applescript.

Applescript ?

Applescript est un service créé par Apple pour exécuter des automatismes sur son ordinateur, afin de faciliter l’exécution de tâches complexes ou répétitives.

Ainsi, pour traduire vos e-mails, voici la méthode, pas simple je l’admets :

  1. Ouvrez l’application Editeur de Scripts
  2. Allez dans le menu Editeur de Scripts – Préférences
  3. Cochez la case Afficher le menu si elle n’est pas cochée
  4. Fermez les préférences
  5. Menu Fichier – Nouveau
  6. Collez le script ci-dessous
  7. Enregistrez-le dans le dossier Scripts de votre dossier [utilisateur]/Bibliothèque sous le nom Traduire un mail
  8. Ouvrez Mail
  9. Choisissez un message en anglais
  10. Cliquez sur l’icône du menu qui ressemble à un petit parchemin, vers la droite
  11. Choisissez votre script
  12. Une fenêtre apparaît avec votre message traduit dans un fichier TextEdit

Note : les points 1 à 7 ne sont à faire qu’une fois. Commencez au point 8 une fois que tout fonctionne.

Le script :

#http://macscripter.net/viewtopic.php?id=31218
#http://macscripter.net/viewtopic.php?id=39742
#The above links are the starting points of this script which both attempt to translate text. But are broken or do not return the full text.

#This script will attampt to translate the text from the selected emails to your chosen language 

property languages_code : {Afrikaans:"af", Albanian:"sq", Arabic:"ar", Belarusian:"be", Bulgarian:"bg", Catalan:"ca", Chinese:"zh-CN", Croatian:"hr", Czech:"cs", Danish:"da", Dutch:"nl", English:"en", Estonian:"et", Filipino:"tl", Finnish:"fi", French:"fr", Galician:"gl", German:"de", Greek:"el", Hebrew:"iw", Hindi:"hi", Hungarian:"hu", Icelandic:"is", Indonesian:"id", Irish:"ga", Italian:"it", Japanese:"ja", Korean:"ko", Latvian:"lv", Lithuanian:"lt", Macedonian:"mk", Malay:"ms", Maltese:"mt", Norwegian:"no", Persian:"fa", Polish:"pl", Portuguese:"pt", Romanian:"ro", Russian:"ru", Serbian:"sr", Slovak:"sk", Slovenian:"sl", Spanish:"es", Swahili:"sw", Swedish:"sv", Thai:"th", Turkish:"tr", Ukrainian:"uk", Vietnamese:"vi", Welsh:"cy", Yiddish:"yi"}

#Curl stuff
property agent : "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_2; en-us) AppleWebKit/531.21.8 (KHTML, like Gecko) Version/4.0.4 Safari/531.21.10"
property charset : "UTF-8"
property header : "Charset:" & space & charset
property theURL : "http://translate.google.com/?"

#used to delimit the html
property snipOpen : "TRANSLATED_TEXT="
property snipClose : ";INPUT_TOOL_PATH"

#You can either set a start language or leave it at auto.
property startLang : "auto"
#set a result language 
property resultLang : French of languages_code

#Ask Mail to get and process selected emails
tell application "Mail"
    set theMessages to (get selection)
    repeat with i from 1 to number of items in theMessages
        set this_item to item i of theMessages

        set thisSender to sender of this_item
        set thisSubject to subject of this_item
        set thisText to content of this_item as string
        my translate(thisSender, thisSubject, thisText)
    end repeat
end tell

(*************** SUBROUTINES *****************)
#Translate the message text and display them in a temp text file
on translate(thisSender, thisSubject, thisText)

    if thisText is not "" then
        #replace all spaces with "%20" for the URL to use without error
        set escapedText to findReplace(thisText, space, "%20")

        #send request  to google and get the returned HTML
        set TranslatedText to do shell script "/usr/bin/curl" & space & ¬
            "-A" & space & quoted form of agent & space & ¬
            "-H" & space & quoted form of header & space & ¬
            "-d" & space & quoted form of ("&ie=" & charset & "&oe=" & charset & "&langpair=" & startLang & "|" & resultLang & "&text=" & escapedText) & space & quoted form of theURL


        try
            #Use delimiters to split the text to just get the actual result part 
            set txt to Split(TranslatedText, snipOpen)'s item 2
            set txt to Split(txt, snipClose)'s item 1

            set displayText to ¬
                "Sender: " & thisSender & "
" & ¬ "Subject: " & thisSubject & "
" & "
" & ¬ txt             #Use Textutil to strip any other rich text or HTML code out and convert to plain text. Then open in a text document do shell script "echo " & quoted form of displayText & "|textutil -format html -convert txt -stdin -stdout | open -f" on error errTxt number errNum display dialog errTxt with title "Error# " & errNum buttons {"Cancel", "OK"} default button 2 with icon 0 giving up after 0 end try end if end translate on Split(txt, del) set {otid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, del} set txt to text items of txt set AppleScript's text item delimiters to otid return txt end Split on findReplace(theString, search_string, replacement_string) if theString contains search_string then set AppleScript's text item delimiters to search_string set text_item_list to text items of theString set AppleScript's text item edelimiters to replacement_string set theString to text_item_list as text set AppleScript's text item delimiters to "" end if return theString end findReplace

Post navigation

Previous Post:

PHP : passage d’une variable dynamique dans une fonction

Next Post:

L’honnêteté sur le Net ?

[Mashup] Canned Heat meets Mar-Keys - Let's work last night
[Remix] Skype Ringtone
  • Blog
  • Dessins
    • 1998 - Arts Appliqués
    • Actualités
    • Compteurs d'eau
    • Dessins divers
    • Divorce
    • Enquêtes
    • GPS
    • Immobilier
    • Informatique
    • Psycho
    • SNCF
    • Vie de couple
  • Ecrits
    • Chanson : Albinoni mélancolique
    • Chanson : Igor le fantôme
    • Chanson : J'ai besoin de vacances...
    • Chanson : Leave me alone
    • Livre : Discours pour la Présidence
    • Livre : L'affaire des brosses à dents
    • Livre : Le lycanthrope contemporain
    • Livre : Mon perfectionnisme
    • Livre : My Ultimate Fonts Collection
    • Poème : Amour
    • Poème : Au revoir
    • Poème : Dévouement
    • Poème : Everlasting
    • Poème : Infidèle
    • Poème : La route est longue
    • Poème : Messages
    • Poème : Ô Nuit
    • Poème : Regard
    • Poème : Romance
    • Poème : Sadness
    • Poème : Un inadapté
    • Poème : Vouloir mourir
    • Poème : Voyage Initiatique
  • Emploi
    • 1999 - Menuisier chez Manpower
  • Liens favoris
  • Musiques
    • 1997 - MODified
    • 2003 - De Inferni Profundis
    • 2006-2007 - Manifest for a generation
    • 2007-2009 - Electrons Libres
    • 2008 - Marcy Playground : Leaving Wonderland
    • 2008-2009 - Mandalas
    • 2008-2010 - Ganadji-Nesis
    • 2008-2016 - Indaba Remixes
    • 2010 - Metric : Fantasies
    • 2011-2013 - Liaisons Covalentes
    • 2012 - Symphonie Electronique
    • 2012-2023 - Mashups
    • 2013-2015 - Lives @ Mistral Palace
    • 2016 - Music Maker Jam (Android)
    • 2016 - Oxydoréduction
    • Morceaux non classés
    • Par genre
      • Ambient
      • Disco
      • Hip-Hop
      • Jazz
      • Nightclub
      • Playlist Soirée Château de Fitou
    • Vidéos musicales
  • Projets personnels
    • Concours divers
    • Fièvre de cheval du samedi soir
    • Language-of.love
    • Projets Web personnels
    • Recyclage Augmenté
    • Réflexions en 3D
    • Squary Movey / Taiketsu-Doku
    • Sudokube / Wordokube / Linkube
  • Qui suis-je ?
  • Travaux graphiques
    • Affiches / Flyers
    • Cartes de visite
    • Jaquettes CD-DVD
    • Logos & Bannières
    • Photomontages
    • Sketchups
    • Weavesilk
  • Tutoriels
    • Installer un serveur web sous Unix
    • L'installation idéale d'un OS
    • Les outils du dépanneur informatique
    • Liste de mes programmes favoris
© 2025 Aurélien STRIDE - Powered by Minimalisticky