Installing xdotool in Linux

Source: Internet
Author: User

Installing xdotool in Linux

  • `
    Have you ever had a dream?
  • -- Your Computer
  • Can I work for you automatically?
  • Maybe not because
  • You just saw Terminator.
  • However
  • Automation of scripts and tasks
  • Is the dream pursued by every senior user
  • If today
  • There are many solutions
  • This goal can be met
  • So
  • Sometimes
  • It's hard to extract from the numerous
  • Simple, intelligent, and efficient
  • Me
  • Cannot pretend
  • I discovered it myself.
  • At the same time
  • But he prefers
  • Clean software-xdotool
  • The method is so intuitive
  • As it is exposed as an X11 automation tool
  • Conversion ideas
  • Xdotool can read text files
  • Simulate the key-hitting melody
  • And manwu with the mouse


Allow Xdotool to settle in Linux

  • For Ubuntu, Debian, or Linux Mint, you can only:

    1. $ Sudo apt-get install xdotool

    For Fedora, use the yum command:

    1. $ Sudo yum install xdotool

    For CentOS users, you can find this package () in EPEL repo (). After enabling the EPEL repository, you only need to use the yum command above to fulfill your wish.

    For Arch users, you can find the package in the Community Repository:

    1. $ Sudo pacman-S xdotool

    If you still cannot find the corresponding xdotool of your release, you can download it from its official site.

    Basic Xdotool skills

    Although xdotool is so intuitive, it is still a script program. Therefore, to use it correctly, you still need to understand its syntax. However, you can rest assured that the syntax is easier to learn than the functions of the program.

    First, it is easy to simulate a key. You can enter the following command from the terminal:

    1. $ Xdotool key [name of the key]

    If you want to connect two keys, you can use the "+" Operator between them. It looks like this:

    1. $ Xdotool key alt + Tab

    You can switch between these two keys.

    To allow xdotool to help you input the data, run the following command:

    1. $ Xdotool type''

    These are sufficient for basic keys. However, one of the many advantages of xdotool is that it can obtain the focus of a specific window. It can get the window on the right and input it in it. All the buttons you record will not evaporate, but will appear exactly as you wish. To obtain this function, a simple command can be used:

    1. $ Xdotool search -- name [name of the window] key [keys to press]

    This command searches for the window with the corresponding name in the window that opens, focuses on the window, and then simulates the shortcut key.

    It is more advanced, but it is very useful. xdotool can simulate moving and clicking the mouse. See this command:

    1. $ Xdotool mousemove x y

    You can position the cursor to the screen coordinates (x, y) (pixels ). You can also use the "click" parameter for combination:

    1. $ Xdotool mousemove x y click 1

    This will move the mouse to (x, y), and then click the left mouse button. "1" indicates the left mouse button, "2" indicates the scroll wheel, and "3" indicates the right mouse button.

    Finally, once these commands are rooted in your mind, you may want to actually dump them to files for editing and try to play. In view of this, there will be more than one statement. You need to write a bash script:

    1. #! /Bin/bash
    2. Xdotool [command 1]
    3. Xdotool [command 2]
    4. Etc

    Or you can use:

    1. $ Xdotool [filename]

    Here you write the command into a separate file, and then use the file name as the parameter of the xdotool command.

    Unexpected gains

    As an unexpected result of this article, here is a specific example of xdotool. You may have heard of or heard of Bing-Microsoft's search engine. In the following examples, you may have never heard of Bing rewards: a program that allows you to use Bing points to redeem Amazon gift cards and other gift cards: I have never heard of it ~). To earn these points, you can search for 30 times on Bing every day, and you will get 0.5 points each time you search. In other words, you must set Bing as the default search engine and use it every day.

    Alternatively, you can use the xdotool script, which will automatically focus on Firefox (you can replace it with your preferred browser ), use the fortune command to generate random words for search. In about 30 seconds, your daily search task is complete.

    1. #! /Bin/bash
    2. For I in {1 .. 30}
    3. Do
    4. WID = 'xdotool search -- title "Mozilla Firefox" | head-1'
    5. Xdotool windowfocus $ WID
    6. Xdotool key ctrl + l
    7. Xdotool key Tab
    8. SENTENCE = "$ (fortune | cut-d'-f1-3 | head-1 )"
    9. Xdotool type $ SENTENCE
    10. Xdotool key "Return"
    11. Sleep 4
    12. Done

    Here is a summary: I really like xdotool, even though its full functionality is beyond the scope covered in this article. This is indeed a simple method for script and task automation. The negative problem is that it may not be the most efficient one. But I want to say it again, it is loyal to its duty, and it is not so troublesome to learn.

    What do you think about xdotool? Do you prefer another automation tool instead of it? Why? Please let us know in the comment.

This article permanently updates the link address:

  • 1
  • 2
  • Next Page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.