Sylvain Gamel m’a gentiment envoyé une copie de son nouveau livre sur Automator « Automatisez sous Mac« , disponible sur l’iBook Store.
En fait j’avoue que c’était la première fois que j’utilisais iBooks, ayant plutôt mes habitudes de livres électroniques du côté de chez Amazon.
Je suis pas un débutant sur Automator, je fais régulièrement en sorte que mon Mac travaille pour moi et pas l’inverse, mais je suis loin d’être un expert comme Sylvain, j’ai donc découvert quelques tuyaux sympas.
A qui se destine cet ouvrage?
Que vous soyez une quiche en informatique ou déjà bien à l’aise sur OSX, il y en a pour tous les niveaux, tout est clairement expliqué avec captures d’écran et vidéos, c’est limpide.
Il est donc tout à fait possible de partir de zéro, ouvrir Automator pour la première fois et devenir un maître Jedi en quelques semaines.
Ce sera aussi l’occasion de se familiariser avec les Dossiers Intelligents, qui sont une fonctionnalité méconnue et largement sous-utilisée du Finder.
Ceci étant dit rentrons dans le vif du sujet, je vais décrire un workflow que j’ai crée inspiré par ce que j’ai découvert dans le livre de Sylvain, comme l’utilisation des variables que je m’étais imaginé plus compliqué que ce qu’elle n’est en réalité.
Scan de calendrier automatique avec utilisation de variable et envoi d’email:
Si vous êtes comme moi vous achetez toujours les cadeaux d’anniversaire au dernier moment, je me suis donc amusé à programmer un workflow pour palier à ce problème. Le résultat n’est pas exactement ce que j’avais prévu au départ, mais il est tout de même pratique et a le mérite d’utiliser un large panel d’actions qui illustrent les possibilités d’Automator, d’où l’intérêt de le partager ici. Vous pouvez aussi moduler cet exemple à souhait pour qu’il réponde à vos besoins.
Une bonne chose à savoir lorsqu’on s’aventure à créer des workflows un peu complexe avec Automator : penser à lire la description des actions, car leur nom n’est pas toujours pertinent.
Résumé du workflow:
Voilà l’objectif:
Toutes les 2 semaines, Automator va scanner mon calendrier pour y chercher les anniversaires à venir, me demander quel est mon idée de cadeau et m’envoyer un email de rappel comprenant le nom de la personne dont c’est l’anniversaire et le cadeau à acheter.
Mise en pratique:
Ouvrez Automator et créez un nouveau workflow, puis insérez les actions ci-dessous, 10 au total que voici:
Si tout ça vous fait peur vous pouvez aussi cliquer sur le bouton ci-dessous pour télécharger le workflow, et l’ajuster à votre guise :
Sélectionner les anniversaires des deux prochaines semaines:
Obtenir les éléments de Calendrier Indiqués:
Sélectionnez ici le Calendrier spécial dans lequel vous ne placerez que les dates anniversaires.
Il existe aussi une action « Rechercher les contacts avec anniversaire » que je n’utilise pas ici car je veux filtrer seulement les gens à qui je souhaite offrir un cadeau.
Filtrer ces évènements Calendrier:
J’utilise cette action pour ne filtrer que les évènements des deux prochaines semaines.
Résumé des évènement:
L’utilisation du résumé est nécessaire pour ‘convertir’ en texte les éléments de calendrier que l’on a filtré avec l’action précédente.
Sélectionner le prénom comme variable:
Éxécuter un script Shell:
Ce script va extraire du résumé le prénom de la personne dont c’est l’anniversaire dans les deux prochaines semaines.
ÉVÉNEMENTS TOTAUX : 1
EVENT 1 OF 1
Summary: Estelle
Status: none
Date: 06/09/2014 to 07/09/2014
Time: 00:00:00 to 00:00:00
Après le script il ne restera que « Estelle« .
Voici le script en question (merci à Sylvain je n’ai pas su le faire tout seul):
/usr/bin/grep 'Summary:' - | /usr/bin/sed -e "s/Summary:\(.*\)/\1/"
Définir la valeur de la variable:
C’est l’action qui va enregistrer le résultat de l’action précédente « Estelle » comme variable que je choisis d’appeler prénom.
Demander et enregistrer l’idée de cadeau:
Demander du texte:
Cette action va afficher une zone de dialogue utilisant la variable prénom et me demandant quelle est mon idée de cadeau.
Voilà le résultat à l’écran:
Le texte rentré ici sera alors enregistré comme nouvelle variable « Cadeau » à travers une autre action « Définir la valeur de la variable« .
Pour manipuler facilement les variables il faut s’assurer que Automator affiche les variables disponibles dans l’onglet en bas de la fenêtre, ce qui n’est qui n’est pas toujours le cas.
Par exemple après une exécution du processus c’est l’Historique qui s’affiche.
Pour re-afficher les variables allez dans Présentation > Variables. Ainsi vous pouvez de nouveau les glisser-déposer facilement dans les actions.
Envoyer l’email:
Cette dernière étape va nécessiter trois actions:
- Nouveau message Mail
- Envoyer les messages de la boîte d’envoi
- Quitter l’application (car je veux pas que Mail reste ouvert)
L’utilisation des variables dans l’objet de l’email permet de s’assurer qu’ils seront tous personnalisés et uniques. Dans l’exemple le résultat sera:
« Anniversaire de Estelle dans 2 semaines, penses à lui acheter un bijou »
Programmer l’exécution automatique:
Dorénavant il n’y a plus qu’à faire en sorte que ce workflow s’éxécute automatiquement toutes les deux semaines, et c’est dans l’application Calendrier que ça se passe.
Créer un évènement – par exemple le lundi matin – dont la récurrence sera de 2 semaines et paramètrez l’alerte sur Personnaliser > Ouvrir le Fichier et sélectionner votre WorkFlow, qui se trouve dans la bibliothèque utilisateur Bibilothèque > WorkFlow > Applications.
Si vous ne voyez pas votre bibliothèque utilisateur ne vous énervez pas Apple à décider de la cacher pour éviter aux débutants d’effacer des fichiers indispensables au bon fonctionnement des applications. Je déplore cette décision mais Apple ne m’a pas consulté 🙂
Pour la faire apparaître lancez le Terminal et exécutez cette ligne de commande:
chflags nohidden ~/Library/
Encore de la marge pour des améliorations pour Automator:
Mon idée première était d’ajouter automatiquement un tâche à Wunderlist, mais cela nécessite un apple script et je n’ai pas le temps de me pencher dessus.
Malheureusement peu d’applications proposent une intégration directe avec Automator (ou des actions propres à l’appli deviennent directement disponibles), c’est d’ailleurs un des éléments que je regarde avant de me décider dans le choix d’une appli.
Deux choses que j’ai trouvé frustrantes:
- impossible de créer un évènement de Calendrier à une date postérieur à la date du jour, c’est bien dommage.
- impossible d’utiliser les variables dans le corps d’un nouveau message Mail, seulement dans l’objet!
Je conseille à tous ceux qu’Automator intéresse d’aller faire un tour sur le blog de Sylvain.
Laisser un commentaire