8

I have an application which is built using GTK+. The application has a very simple interface. When started, the same window always opens, with a few input controls.

We want to write a script to fill in text in a couple fields, check a check box, then click a button. Pretty simple, and would be easy to do if a command-line version of the app were available (but it isn't).

What's the best way to approach interacting with an X application programmatically?

9

Give xdotool (Ubuntu man page) a look.

It's extremely powerful and should be able to do whatever you need.

http://www.semicomplete.com/projects/xdotool/xdotool.xhtml

  • i think the use of xdotool should only be considered in real emergency cases! Scripting something serious with xdotool is more a pain than a pleasure. Before you try xdotool ask the developer if the application has a dbus interface. That would make your plan much simpler. – user1146332 Jul 26 '13 at 14:20
  • 1
    @user1146332 I am using xdotool for various tasks without problem. I don't know what exactly more a pain than a pleasure is based on. – LinuxSecurityFreak Mar 23 '18 at 5:55
  • I'm using xdotool in a similar situation, and one thing that is a pain is that it can't look at the window to which it is sending events. One issue is nondeterministic timing: If the X program needs some time to process one event and would ignore the next event when it came too early, you need to add generous sleep pauses, but you never know how long is long enough. – Hans-Martin Mosner Mar 23 '18 at 6:19
3

xte, part of xautomation is another tool that you can use to generates fake X11 input using the XTest extension.

From the homepage:

Control X from the command line for scripts, and do "visual scraping" to find things on the screen. The control interface allows mouse movement, clicking, button up/down, key up/down, etc, and uses the XTest extension so you don't have the annoying problems that xse has when apps ignore sent events. The visgrep program find images inside of images and reports the coordinates, allowing progams to find buttons, etc, on the screen to click on.

-1

Xte works but it is really old. xdotool is at least in active development.

I did a lot of study of generating X Windows events, nominally to develop a keyboard macro program that can type strings, or the clipboard in applications that normally do not allow you to use paste.

X Window Event Handling Notes... http://www.ict.griffith.edu.au/anthony/info/X/event_handling.txt

Keyboard Macro (using xte or xdotool http://www.ict.griffith.edu.au/anthony/software/#keyboard_macro

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.