Episode: 1996 Title: HPR1996: Xdotool magic Source: https://hub.hackerpublicradio.org/ccdn.php?filename=/eps/hpr1996/hpr1996.mp3 Transcribed: 2025-10-18 13:01:26 --- This is HPR Episode 1996 entitled, Ex-Total Magic, and is part of the series, Lightway Tapes. It is hosted by Acho Jordan and is about 18 minutes long. The summary is over new and a few usage possibilities on the Ex-Total Program. This episode of HPR is brought to you by an honesthost.com. Get 15% discount on all shared hosting with the offer code, HPR15, that's HPR15. Better web hosting that's honest and fair at An Honesthost.com. Hello, this is Nacho Jordan and you're listening to Hacker Public Radio. Today I'm going to discuss a little program called X22, which I would probably have better include in the episode about what's in my bag. I just remember it later. So this is a very simple podcast where I want to repair that injustice. Because X22 is also one of those programs that I install in every computer that's in my possession, because it's a very useful tool and that allows you to do a lot of great stuff. So what is X22 and what can I do? X22 basically it's a little program that you run from the terminal or from a bus script that allows you to simulate user input from either keyboard or mouse. So in other words, what the X22 does is tricking your computer into thinking that you've pressed a key or you've done something with the mouse. For example, you can trick the computer into thinking that you've typed a certain word or moved with the cursor keys or pressed enter or tab. It's not limited to letters, but anything that's in the keyboard pretty much. Well, most of it I haven't tried the most weird keys, but you can pretty much do anything you can do with your 10 fingers. You can do it with X22. In the mouse side of things, you can tell it to move the cursor around. You can both in relative coordinates then absolute. And you can simulate a left click, middle click, right click, also just as a punctual click, like when you click on a link or keeping the mouse button sustain hold. As you can imagine, this opens a whole world of possibilities of things where you can automate things. The syntax of the command is X22, a certain command of what you want to do with a keyboard or a mouse. And it's pretty straightforward. For example, X22 key. And then you put the letter, the key, you want X22 to type to tell the computer that it has been typed. And the only tricky thing about the X22 syntax perhaps is the special keys, not alphabet keys. For example, for enter, you have to use X22 key return. And also the return has the first letter in as a capital letter. So it took me some time to find this essential shortcut. And it doesn't appear very clear in the documentation. It would be nice if someone would provide a list of all these special keys like return or the tab key, etc. So with once you have the tool installed, it's very easy to install. Not a lot of dependency health. It's pretty straightforward. With this program then you can do a lot of things like I say to automate stuff. For example, one thing that I've done very often because I always like to start with the hardest things first, it seems. I've automated the data introduction. Some websites that can be very boring and make the tasks very repetitive. Websites that are not very well designed or don't have the user in mind as much as the design and the colors. If the task is big enough, you can maybe say good idea to make a tiny script that automates a few movements. This depends a lot on the web and on the task you're doing. Our H is in a way the rise of bureaucracy because due to computers there is a form for everything. You have to be feeling formed all day in all kinds of contexts. If you want to have your ceiling repaired, everything needs a form now. Sometimes it's useful to create a small bash robot. Because X2 and other things that allows is the mouse wheel. It has the whole range of movements that a mouse can allow. One limitation of doing this is that when you're working with websites, you will not always predict how long it's going to take to download the page. This is what makes this idea somewhat impractical. If you don't know how long the website is going to take, you can find your way through a process. You can map the process of what you do in a website. Let's say it's a website for example where you introduce images and they have to click somewhere and then go through a menu to change the order of the picture or something like that. You can do a first iteration very slow and saying okay this is the process so now I can write the X to two scripts. But as you cannot predict how long it's going to take going from website to page A to page B. Your only solution is creating a buffer of let's say two to three seconds to make sure that the second page is loaded before X to two resumes doing its thing. So there you lose part of the savings of the time savings that you were intending to get with your script. Anyway, sometimes it's still a better idea. It's still a good idea but not always because for example you need an example of the website to upload images. You have to be present to insert the images so there it's a bit nerve breaking using the robot but because in the end you have to wait for the computer to load. So this kind of I mean it's very it's very very tiresome on your nerves when you have to do something then wait three seconds then do something then wait three seconds. Even if it's automated it's a bit the automation is not comfortable for you at least in my case. I think the cost the energy cost of starting and stopping all the time it's a bit straining but this kind of automation can be useful in websites where you can automate the whole thing, the whole process you don't have to you can run the script once you've made sure it's stable and just go and do something else while the computer finishes its process. And also as a bonus let's say you cannot deny that it's very spectacular one of these scripts running and when you can see the computer doing stuff on its own and typing on its own it's like a science fiction movie. But that's a that's a Charlie's advantage but well I wanted to mention it too. So okay this kind of automation of sites and has its limitations I still have a couple of scripts in my computer that I can go to scripts for a site time certain tasks but like I say it's a bit can be a bit tricky. Well I found more useful using X2 it's a I created a small wrapper script and it's like a type of robot. It's like a coma it would be like an echo coma let's say it's not called echo it's called something else where like you say let's say in your computer please type this for me and this wrapper can be used in a lot of contexts. Yeah and connected to this type of robot the other great users I've found is for example I to put a timestamp to two things. That's that's a that role was I use it a lot a simple key press and I have a year months day and hour that I cannot do a script or to a text file and that's very very useful. The way I started using this kind of timestamps maybe the Serbs are a comment it all started with when I I I read in a blog post from a guy called Dr. Bansson. As this then he uses to classify his his files what he does is adding this kind of timestamp to in the file name and then using the file name as a placeholder for tax let's say and then instead of using a file trees system with high hierarchies he has it all the files. In the same pool let's let's say and locate the files using search comments it's an interesting approach I used it for a long time but I found the long file names can be confusing sometimes and most of the time or on many occasions for the uses that I give to my computer what would you end up having is a lot of information that you don't need in the in the file name of a lot of clutter. So of course Dr. Bansson is like a biologist I think so his needs are different from mine and I like to try this this approach the tags are very useful in some context. But in any way I I move to a different system but I kept this this timestamp and in a lot of tasks I'm always finding new uses for it because I mean having a way to register at what time something happens it's it's a very sensual thing and as a side note I've never understood. But I do very well why are are funding fathers the founding fathers of Unix the industry and can sometimes why didn't they include the creation date a field in in the in the files files have a last time modified information but I don't think that's as useful as having when a file was created because it provides you with an instant chronology of use. So your work and of your of your life of course a Unix as we all know is rock solid and and our funding fathers would have a serious reasons behind maybe because they were on a business context on this kind of information is not that useful. But it would be great because even if you're a disorganized person who uses Linux and at some point you get the age to become organized a having a creation time of a file would allow you to to see that chronological perspective I'm sure I'm sure speak out of ignorance and there's a good reason for that like for most of the things we know and love in Unix and Linux. So anyway I use this timestamp thing and also related to the to the automatic typing and to time in a way to I've also developed a small script that I call coronal text that does that works like like this when I press a key the computer tells me okay I've started counting. Then I do whatever I'm doing and when I press that key again the computer types how many seconds have passed. It's like a mega straight forward chronometer and I'm finding more I'm always to use it because yeah because my idea was creating a chronometer that that was took all the stuff out of the way I didn't want to have a new window opening I didn't want to have to look for that program. So yeah the key press I'm in the text and then that type that type that text that types itself automatically depending on the task can register or I can just take a look at it and then letting it go etc. So yeah it's a script that works very well for me I'm not including it because I think it's a very specialized kind of thing and I don't think anybody's interested in it. But if anybody would like this of course I just contact me and I will send you the code but it's also a very trivial code. So I guess most Hacker Public Radio listeners would better like to write their own versions that using my script but if you're interested in this or the other type of robot of course I can send you the code. And that's all I have for you today is in the short notes I'll give you links to the x2 tool and it's a funny addition to your system I encourage you to at least give it a try because it's really very easy to install. So thank you for listening one more time and well have a nice day thank you very much bye. You've been listening to Hacker Public Radio at Hacker Public Radio. We are a community podcast network that releases shows every weekday Monday through Friday. Today's show like all our shows was contributed by an HBR listener like yourself. If you ever thought of recording a podcast and click on our contributing to find out how easy it really is. Hacker Public Radio was founded by the digital dog pound and the infonomicum computer club and it's part of the binary revolution at binrev.com. If you have comments on today's show please email the host directly leave a comment on the website or record a follow-up episode yourself. Unless otherwise status today's show is released on the creative comments, attribution, share a light 3.0 license.