Outils pour utilisateurs

Outils du site


issue149:tutoriel1

Ceci est une ancienne révision du document !


We will be using xdotool: https://www.semicomplete.com/projects/xdotool/ Here is a story for you to read; it involves a guy who automated everything that took any of his time: https://www.businessinsider.com/programmer-automates-his-job-2015-11?IR=T Though his scripts were in Ruby, it presents an interesting angle. Though I will not be showing you how to automate sending text messages to your boss when you have a hangover, I will try to start you on the path to automating things in Ubuntu. What you will need: A computer running Ubuntu Linux (I am using Xubuntu). Geany. A learning mindset.

Nous utiliserons xdotool : https://www.semicomplete.com/projects/xdotool/

Voici une histoire que vous pouvez lire : dedans, un gars automatise tout, ce qui lui prend tout son temps : https://www.businessinsider.com/programmer-automates-his-job-2015-11?IR=T

Malgré ses scripts en Ruby, elle présente un angle intéressant. bien que je ne vous montrerai pas comment automatiser l'envoi de messages texte à votre patron quand vous êtes planté, j'essaierai de vous faire prendre le début du chemin de l'automatisation avec Ubuntu.

Ce dont nous avons besoin : Un ordinateur tournant sous Linux (j'utilise Xubuntu). Geany. Un esprit ouvert à l'apprentissage.

Before we begin, I want you to look at the xdotool man page. You can also type: xdotool - -help to see a list of valid commands. Let us start by creating an empty file, naming it myscript.sh, and making it executable. If this is your first time - touch myscript.sh chmod +x myscript.sh Now open the file (myscript.sh) with Geany and insert the following: mousepad& sleep 1 xdotool type “I am too lazy to type this over and over again”

Avant de commencer, je veux vous montrer la page man de xdotool. Vous pouvez taper aussi xdotool –help pour voir une liste des commandes valides.

Commençons par créer un fichier vide, appelons-le myscript.sh et rendons-le exécutable.

Si c'est la première fois pour vous -

touch myscript.sh

chmod +x myscript.sh

Maintenant, ouvrez le fichier (myscript.sh) avec Geany et insérez ce qui suit :

mousepad&

sleep 1

xdotool type “Je suis trop paresseux pour taper ceci en permanence”

I am using mousepad, as I am on Xubuntu, but you may have another text editor, like leafpad or featherpad. Please feel free to substitute your text editor. So let us dissect it. • We start mousepad. • We pause for a second – I will tell you why * • We type something in mousepad. If you are using Geany, you have a terminal in your bottom pane. If not, open a terminal and run the script: ./myscript.sh The terminal is fast, much faster than GUI programs, if we do not pause to wait after opening mousepad, half of out text will be in the terminal and half inside notepad.

J'utilise mousepad, car je suis sous Xubuntu, mais vous pourriez avoir un autre éditeur de texte, comme leafpad ou featherpad. N'hésitez pas à le remplacer par votre éditeur de texte.

Détaillons son contenu.

••Nous lançons mousepad ••Nous faisons une pause d'une seconde - Je vous dirai pourquoi * ••Nous saisissons quelque chose dans mousepad

Si vous utilisez Geany, vous avons un terminal dans le bandeau du bas. Sinon, ouvrez un terminal et lancez le script :

./myscript.sh

Le terminal est rapide, beaucoup plus que les programmes en affichage graphique ; si vous ne faîtes pas une pause après avoir ouvert mousepad, la moitié de votre texte sera dans le terminal et le reste dans notepad.

Ever wonder how something spookily types notes on a computer in the movies? Now you know! How about simulating key-presses? Key presses are as simple as typing the key you want pressed, or combination of keys, first key followed by the plus sign ‘+’ and the second key. For now append the following line to your code and run it. xdotool key F1 This will launch the help file right after typing your message. How about we save our mousepad file instead of opening help? If you click on “File” in your text editor window, chances are you will see ‘Save’ and ‘Ctrl+S’ as the shortcut key next to it. The way that you simulate the Enter-key is: xdotool key KP_Enter

Vous vous êtes toujours demandé comment quelque chose d'obscur tape des notes sur un ordinateur dans les films ? Maintenant vous savez !

Comment simuler l'appui sur les touches ?

L'appui sur les touches est aussi simple que de taper la touche sur laquelle vous voulez appuyer, ou une combinaison de touches, la première touche suivi du signe « + » et de la seconde touche. Maintenant, ajoutez la ligne suivante à votre code et lancez-le.

xdotool key F1

Ceci lancera le fichier d'aide juste après avoir taper votre message. Comment sauvegarder votre fichier mousepad au lieu de l'ouvrir ? Si vous cliquez sur « Fichier » dans la fenêtre de votre éditeur de texte, il y a des chances que vous voyiez « Enregistrer » et « Ctrl+S » qui est son raccourci. La façon de simuler Ctrl+S est :

xdotool key KP_Enter

Your homework is to name your text file ‘test.txt’ and save it. You have everything you need to do it. So do it. I will show you how I did it in the next issue and we will continue with our automation journey with more hands-on examples. We will also go into mouse movement and clicking. Feel free to contact me on Telegram if you have any questions.

Votre travail à la maison est de nommer votre fichier texte « test.txt » et de l'enregistrer.

Vous avez tout le nécessaire pour le faire. Donc, faîtes-le. Je vous montrerai comment je le fais dans le prochain numéro et nous continuerons notre voyage dans l'automatisation avec d'autres exemples pratiques. Nous verrons aussi les mouvements de la souris et les clics.

N'hésitez-pas à me contacter sur Telegram si vous avez des questions.

issue149/tutoriel1.1571117852.txt.gz · Dernière modification : 2019/10/15 07:37 de d52fr