3

Effectively, I am looking for an AutoIt clone for Linux.

I am aware of tools like Sikuli, Javaauto, etc, but they just won't cut it, because they rely on x, y coordinates and for example they are unable to find a window or menu item based on its title text.

I want something that I can find the window based on its title, or be able to click the button labelled 'OK'.

I have Googled and I have checked out this SuperUser question and this five year old S.o question - from which I shall now proceed to shamelessly copy large parts, as the OP @Xeddy made such a good job of stating the requirements.

Here’s a simple, sample script:

Run("notepad.exe")
WinWaitActive("Untitled - Notepad")
Send("This is some text.")
WinClose("Untitled - Notepad")
WinWaitActive("Notepad", "Save")
Send("!n") 

Run the script and you'll see Notepad open, some text appear and then close.

Now the above example, although a bit pointless, is a demo of the sort of functionality and simplicity I'm looking for. Here's an explanation for those who don't speak AutoIt:

----Start of Explanation of Code ----

Asks user to input some text and stores it in varInput
Runs notepad.exe
Waits till window exists and is active
Sends the contents of varInput as a series of keystrokes
Sends keystrokes to go to File -> Exit
Waits till the "Save" window is active
Sends some more keystrokes

Shows a Message Box with some text and the contents of a variable

Registers a hotkey, Win+N, which when pressed executes notepad.exe

----End of Explanation----

So as you can understand, the features are quite obvious: Ability to easily simulate keyboard and mouse functions, read input, process and display output, execute programs, manipulate windows, register hotkeys, etc.. all being done without requiring any #includes, unnecessary brackets, class declarations etc. In short: Simple.

Perhaps the single greatest thing about AutoIt, which all others seem to lack is that it does not rely on x,y coordinates - one can search for a window by title (even wait for it to appear).

Plus AutoIt uses a Basic-like scripting language, with normal programming concepts like IF statements, loops, etc

Is there anything quite so powerful for Linux?

  • Please expand a little on why Sikuli and javaauto doesn't cut it, to further help people understand your requirements. – holroy Aug 11 '15 at 11:11
  • I can't see how to reword it. The drawbacks of others are 1) the reliance on x,y coordinates and 2) the inability to find a window or menu item based on its title text – Mawg Aug 11 '15 at 11:31
  • Maybe : wiki.actiona.tools/doku.php?id=en:start – willll Aug 12 '15 at 20:31
  • Alas, that too relies on X,Y coordinates. I can't tell it to click the button labelled OK – Mawg Sep 23 '15 at 8:26
  • You mean controlling X windows, Wine apps (like Notepad under Linux), or in specific window manager (like KDE, GNOME)? – kenorb Jun 2 '17 at 12:09
2

In Linux you can use the shell scripting (such as Bash) along with relevant command-line tools described below.

xdotool

This is a command-line tool for faking input from the mouse and keyboard. It also supports window manager actions such as moving, activating, and other actions on windows.

Home page: jordansissel/xdotool at GitHub

Install via: sudo apt-get install xdotool

Sample script example:

WID=$(xdotool search --name "Some Window Title")
xdotool key --window $WID --delay 500 space Tab Return Tab space Alt+n

Related: How to programatically control X11 forwarded apps?


X utils

There are command-like tools for managing windows and display for X apps such as xwininfo, xdpyinfo, xprop and other (check the man for more details). Along with already mentioned xdotool, they can be used as part of the shell script to automate and control X windows.


expect

There is a expect command line and it's used for controlling terminal processes. So if your GUI application can be controlled by the command-line and return some output, this is the tool you can use.

For example you can use mix it with xdotool:

#!/usr/bin/expect
set timeout 360
spawn some_GUI_command & # Replace with your command.
WID=$(xdotool search --name "My GUI Title")
xdotool set_window --overrideredirect 1 $WID windowunmap $WID windowmap $WID
xdotool windowsize $WID 10 100%
xdotool behave $WID mouse-enter windowfocus windowsize --usehints 80 100% &
xdotool behave $WID mouse-leave windowsize 4 100% &
xwininfo -id $WID -tree
expect "Setup" { xdotool key --window $WID --delay 500 Tab Return }

Note: Above is just a pseudo-code example, I haven't tested the above code. It is just used for the reference.


AutoHotkey (AHK)

For controlling Windows apps under Linux such as notepad.exe, you can use AutoHotkey (AHK) in Linux by executing it under Wine. This is how winetricks is using it in Linux (see w_ahk_do() in src/winetricks), e.g.

wine AutoHotkey.exe script.ahk

AutoHotkey supports scripting language and it's very underrated powerful tool. For some code examples check Stack Overflow.


AutoIt

The same as above, you can run AutoIt under Wine.

The AutoIt Editor SciTE 3.3.0 runs flawlessly. Writing programms, building or compiling them is possible. I did not try to run them inside wine, as it seems senseless. Au3Check.exe, Au3Info.exe, AutoIt3.exe start without any trouble.


See also: Comparison of GUI testing tools at Wikipedia

For some Python automation libraries, see:

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.