Add the following code to your project's shard.yml under:
dependencies
to use in production
- OR -
development_dependencies
to use in development
AutoHotkey for Linux.
MsgBox, AHK_X11
(*)
This project is usable, but WORK IN PROGRESS.
Scripts from Windows will usually NOT WORK without modifications. If you want this to become a reality, you're welcome to contribute, and/or join the AHK Discord's #ahk_x11 channel.
Requires X11, does not work with Wayland yet. This is important for Ubuntu version 22.04 and up (link)
Direct download (all Linux distributions, x86_64, single executable)
FULL DOCUMENTATION (single HTML page)
Go to installation instructions
DEMO VIDEO: Installation, script creation, compilation
AutoHotkey is "Powerful. Easy to learn. The ultimate automation scripting language for Windows.". This project tries to bring large parts of that to Linux.
More specifically: A very basic but functional reimplementation AutoHotkey v1.0.24 (2004) for Unix-like systems with an X window system (X11), written from ground up with Crystal/libxdo/gi-crystal/x11-cr/x_do.cr, with the eventual goal of 80% feature parity, but most likely never full compatibility. Currently about 60% of work is done. This AHK is shipped as a single executable native binary with very low resource overhead and fast execution time.
Note that because of the old version of the spec (at least for now), many modern AHK features are missing, especially expressions (:=
, % v
), classes, objects and functions, so you probably can't just port your scripts from Windows. More to read: Project goals
You can use AHK_X11 to create stand-alone binaries with no dependencies, including full functionality like Hotkeys and GUIs. (just like on Windows)
Please also check out Keysharp, a WIP fork of IronAHK, another complete rewrite of AutoHotkey in C# that tries to be compatible with multiple OSes and support modern, v2-like AHK syntax with much more features than this one. In comparison, AHK_X11 is a lot less ambitious and more compact, and Linux only.
Features:
Besides:
AHK_X11 can be used completely without a terminal. You can however if you want use it console-only too. Graphical commands are optional, it also runs headless.
DONE 42% (93/219):
+ Else, { ... }, Break, Continue, Return, Exit, GoSub, GoTo, IfEqual, Loop, SetEnv, Sleep, FileCopy,
+ SetTimer, WinActivate, MsgBox, Gui, SendRaw, #Persistent, ExitApp,
+ EnvAdd, EnvSub, EnvMult, EnvDiv, ControlSendRaw, IfWinExist/IfWinNotExist, SetWorkingDir,
+ FileAppend, Hotkey, Send, ControlSend, #Hotstring, Menu, FileCreateDir, FileDelete, IfMsgBox,
+ #SingleInstance, Edit, FileReadLine, FileSelectFile, FileSelectFolder, FileSetAttrib, FileSetTime,
+ IfNotEqual, If var [not] between, IfExist/IfNotExist, IfGreater/IfGreaterOrEqual,
+ IfInString/IfNotInString, IfLess/IfLessOrEqual, IfWinActive/IfWinNotActive, IniDelete, IniRead,
+ IniWrite, Loop (files & folders), Loop (read file contents), MouseClick, Pause, Reload,
+ StringGetPos, StringLeft, StringLen, StringLower, StringMid, StringReplace, StringRight,
+ StringUpper, Suspend, URLDownloadToFile, WinClose, WinGetPos, WinKill, WinMaximize, WinMinimize,
+ WinMove, WinRestore, MouseGetPos, MouseMove, GetKeyState, KeyWait, ControlClick, WinGetText,
+ WinGetTitle, WinGetClass, PixelGetColor, CoordMode, GuiControl, ControlGetPos, ControlGetText,
+ WinGet, Input, Loop (parse a string), ToolTip, If var [not] in/contains MatchList, ControlSetText,
+ PixelSearch, #Include
NEW 4% (8/219): (not part of spec or from a more recent version)
@@ Echo, ahk_x11_print_vars, FileRead, RegExGetPos, RegExReplace, EnvGet, @@
@@ ahk_x11_track_performance_start, ahk_x11_track_performance_stop @@
REMOVED 5% (12/219):
# ### Those that simply make no sense in Linux:
# EnvSet, EnvUpdate, PostMessage, RegDelete, RegRead, RegWrite, SendMessage, #InstallKeybdHook,
# #InstallMouseHook, #UseHook, Loop (registry)
#
# ### Skipped for other reasons:
# AutoTrim: It's always Off. It would not differentiate between %a_space% and %some_var%.
# It's possible but needs significant work.
TO DO 47% (102/219): alphabetically
- BlockInput, ClipWait, Control, ControlFocus, ControlGet, ControlGetFocus,
- ControlMove,
- DetectHiddenText, DetectHiddenWindows, Drive, DriveGet, DriveSpaceFree,
- FileCopyDir, FileCreateShortcut,
- FileInstall, FileGetAttrib, FileGetShortcut, FileGetSize, FileGetTime, FileGetVersion,
- FileMove, FileMoveDir, FileRecycle, FileRecycleEmpty, FileRemoveDir,
- FormatTime, GroupActivate, GroupAdd,
- GroupClose, GroupDeactivate, GuiControlGet,
- If var is [not] type,
- InputBox, KeyHistory, ListHotkeys, ListLines, ListVars,
- MouseClickDrag, OnExit,
- Process, Progress, Random, RunAs, SetBatchLines,
- SetCapslockState, SetControlDelay, SetDefaultMouseSpeed, SetFormat, SetKeyDelay, SetMouseDelay,
- SetNumlockState, SetScrollLockState, SetStoreCapslockMode, SetTitleMatchMode,
- SetWinDelay, Shutdown, Sort, SoundGet, SoundGetWaveVolume, SoundPlay, SoundSet,
- SoundSetWaveVolume, SplashImage, SplashTextOn, SplashTextOff, SplitPath, StatusBarGetText,
- StatusBarWait, StringCaseSense, StringSplit, StringTrimLeft, StringTrimRight,
- SysGet, Thread, Transform, TrayTip, WinActivateBottom,
- WinGetActiveStats, WinGetActiveTitle,
- WinHide, WinMenuSelectItem, WinMinimizeAll,
- WinMinimizeAllUndo, WinSet, WinSetTitle, WinShow, WinWait, WinWaitActive,
- WinWaitClose, WinWaitNotActive, #CommentFlag, #ErrorStdOut, #EscapeChar,
- #HotkeyInterval, #HotkeyModifierTimeout, #MaxHotkeysPerInterval, #MaxMem,
- #MaxThreads, #MaxThreadsBuffer, #MaxThreadsPerHotkey, #NoTrayIcon, #WinActivateForce
Also planned, even though it's not part of 1.0.24 spec:
- ImageSearch
- Maybe some kind of OCR command
- #IfWinActive (the directive)
Download the latest binary from the release section. Make the downloaded file executable (how?) and you should be good to go: Just double click it or run it in the console without arguments (without sudo).
Prerequisites:
There is no auto updater yet! (but planned) You will probably want to get the latest version then and again.
There are different ways to use it.
.ahk
files are associated with AHK_X11, so you can simply double click them.Open as...
Menus../ahk_x11 "path to your script.ahk"
echo $'var = 123\nMsgBox %var%' | ./ahk_x11
~/.local/bin/ahk_x11.AppImage
%ErrorLevel%
will always be 0
.--repl
instead (implicit #Persistent
)../ahk_x11 --compile "path/script.ahk"
./ahk_x11 --windowspy
#!
DISPLAY= ./ahk_x11 <<< 'Echo abc'
just prints abc
to the console (Echo
command is a special ahk_x11-only command). The only advantage is faster startup time.All commands or command options related to Controls (e.g. ControlClick
or WinGetText
) relies on assistive technologies. While almost all windows support this, this typically needs adjustments on the running system. Read the documentation section on accessibility for instructions.
Some Linux distros offer a configurable setting for focus stealing prevention. Usually, it's default off. But if you have activated it, window focus changing actions like MsgBox
or WinActivate
will not work as expected: A MsgBox
will appear hidden behind the active window. This can be useful to prevent accidental popup dismissal but when you don't like that, you have three options:
disable said setting
use the always on top
setting of MsgBox
SetTimer, MsgBoxToFront, 1
MsgBox, Hello
Return
MsgBoxToFront:
SetTimer, MsgBoxToFront, off
; You might want to adjust the matching criteria, especially for compiled scripts
WinActivate ahk_class ahk_x11
return
(*) The MsgBox
picture at the top was taken on a XFCE system with Chicago95 installed, a theme that resembles Win95 look&feel. On your system, it will look like whatever GTK popups always look like.
Like covered above, AHK_X11 is vastly different to modern Windows-AutoHotkey because 1. its spec is missing its more recent features and 2. there are still several features missing. Apart from that, there are a few minor incompatibilities between AHK_X11 and the then-Windows-AutoHotkey 1.0.24:
#NoEnv
is the default, this means, to access environment variables, you'll have to use EnvGet
.Besides, it should be noted that undocumented == undefined.
AHK_X11 is an interpreted language, not a compiled one. This means that no compile time optimizations take place on your script code, apart from some validation and reference placements. Also, all variables are of type String. So you probably wouldn't want to use it for performance-critical applications. However, the tool itself is written in Crystal and thus compiled and optimized for speed, so everything should still be reasonably fast. The speed of some of the slower commands depends on either libxdo or X11 and it's not yet clear whether there is much room for improvement. Some tests run on a 3.5 GHz machine:
Parsing a single line takes about 30 µs (this happens once at startup), and execution time depends on what a command does:
x = 1
: 70 ns (0.00000007 s)FileRead, x, y.txt
: 10 µs (0.00001 s)WinGetTitle, A
: 87 µs (0.000087 s)Send, a
: 530 µs (0.00053 s)Clipboard = a
: 6 ms (0.006 s)SendRaw, a
: 9 ms (0.009 s) (??)WinActivate, title
: 60 ms (0.06 s)WinGetText
: 0-3 s (!)You can run fine-grained benchmarks with the following special hidden instruction:
AHK_X11_track_performance_start
Loop, 1000
Send, a
AHK_X11_track_performance_stop
prints something like:
[{"send", count: 1000, total: 00:00:00.530032328>},
{"loop", count: 1001, total: 00:00:00.000206347>}]
Note that the internal code around executing commands takes about 10 µs between two every commands and you can't do anything about it and this not measured / included in the benchmark command's output. This can actually be the bottleneck in some scripts and should probably be improved
More tips:
Control
-*, WinGetText
, ... see "Accessibility" section above) runs, the interface needs to be initialized which can take some time (0-5s)WinActivate, ahk_id %win_id%
will be much much faster than WinActivate, window name
. So for many window operations you might want to do a single WinGet, win_id, ID
beforehand and then reuse that %win_id
.If you want to help with AHK_X11 development or prefer to build from source instead of using the prebuilt binaries, detailed build instructions are to be found in ./build/README.md.
For bugs and feature requests, please open up an issue, or check the Discord or Forum.