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.

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”

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.

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

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.

issue149/tutoriel1.1569912824.txt.gz · Dernière modification : 2019/10/01 08:53 de d52fr