Why this write up? I just gave AHK a real look this last week, and while I can see its usefulness on Windows, most, if not all of it's functions can be replicated with the *nix shell environment. This is not a full-on instructional, but more of a basic overview for any linux users (or those curious, dual-booters, etc), n00b or veteran, who would like to utilize automated tasks. I can't think of a single thing that shell cannot do, with the help of a utility called xbindkey.
That's it, that's all you need! Though, you can USE anything and everything else in the linux world to your advantage here.
What I'm presenting to you, is that Shell scripting language can be used much in the same way as AHK.
Again, I'm not going to get into script-writing, tell you how to do something done with AHK in shell, or anything like that. While I may respond to some requests, I probably won't, I'm a jerk, and I like people to learn how I did, through experience, trial, and error.
###########################################################################################################################
Before I get into the nitty-gritty, I'd like some input, AHK is open-source, and while I haven't looked at the source code, I'm sure it can be rewritten/ported over to both Linux and Mac OSX. While tedious, it wouldn't be too difficult. The reason I believe it hasn't already, is because many that could, that use linux, already know how to do things it does, on our systems. That said, I wouldn't mind taking on the project IF there is sufficient need, and demand. Let me know what you think!
Second thing. I haven't even searched Has anyone made any attempt at a port that ISN'T written in C#? I'm hoping for C++, Python or even C. If not, eh, I'd rather not work on top of someone else anyway, but I'd also rather not waste my time!
I promise I will search after I'm done here
My goal would not only be to be able to replicate function, but maintain compatibility with some AHK scripts! Much like wine does for the ENTIRE Win32 API, but only for those essential to the language.
###########################################################################################################################
The interactive shell is a god-send for automation, (the Windows command prompt, as well as PowerShell, are great tools as well, and I still dualboot Windows, but it doesn't shake a stick at the flexibility of a *nix Shell) maybe the one thing AHK does better is automation of gui (ie, if this appears on screen, click it!), luckily, most programs can be controlled from commandline anyway, so I don't have too much use for it YET! Also, wmctrl allows for command line control over X Window Manager, so even if a program lacks command line function, I can manipulate it that way. Really, the only thing I haven't used prior, is mouse movement and gui manipulation with it, as I've never had a need before. I'm sure it's easily done, I just haven't looked at it. If someone knows of a utility that helps with this, let me know so I can add it here (as well as maybe even finding a use for it!).
You only need a few things to implement your "ahk-like" abilities
Shell (bash, zsh, etc. I prefer zsh) aliases and scripting,
and a few nifty programs like xbindkeys (let's you bind things to keys and mouse, like AHK), xdotool (allows you to simulate keyboard and mouse input), and wmctrl (let's you manipulate GUI windows)
The combination of xbindkeys, shell and a good bash profile can accomplish much the same as AHK, and the inclusion of wmctrl lets you manipulate GUI windows with it. I can bind any shell commands/scripts/functions to an alias, then bind that alias to key with xbindkeys
A VERY BASIC INTRO TO BASH SCRIPTS, ALIASES, AND HOW THEY CAN BE AUTOMATED. MUCH OF THIS WILL REQUIRE RESEARCH OR KNOWLEDGE ON YOUR OWN, GOOGLE IS YOUR BESTEST FRIEND!
Pro-tip, 99.9% of shell commands have a manual, that can be reached by typing
$ man command
^ DO NOT TYPE THE $, this means shell. First and only time I'm saying this.
You will need to open .bashrc (or .zshrc etc if zsh), this is essentially your config file, where you can include your own alias / commands / functions.
$ vim ~/.bashrc
(if unfamiliar with vim, which is a command line text editor, substitute your typical editor, ex. $ gedit ~/.bashrc )
then, scroll to the bottom, and comment a section for Aliases (any line that begins with # is a comment, and is not interpretted
Code: Select all
###########################################################
#My aliases and a handful of useful conditional statements#
###########################################################
#typical alias syntax
alias aliasname='command'
#every alias will begin with the word alias, followed by what you want it to be named, and then the command(s) it should run. Example=
alias sagi='sudo apt-get install'
#Obviously this would have little use for automation, but I wanted to use a command you are likely familiar with
#You can chain commands with the && operator
alias chainedalias='commands && more_commands && EVEN_MORE_COMMANDS'
#Once the alias is created, next time you open Shell, you can type aliasname, then hit enter to run the alias
#For example,
$ sagi gimp
#would be the same as
$sudo apt-get install gimp
#From here, you can use xbindkey to assign your new alias to a key or mouse combo, woo!
#Why am I still commenting on a forum post?!
You can also add functions, or conditional statements to your .bashrc, and they can be huge for automation, but google can easily help you with that.
What are useful, SCRIPTS!, whether in bash syntax, or any other language.
It will be up to you to figure out how, and learn to write said scripts, that's beyond this write-up, and many better than me, have written about them.
To make them useful to use for this purpose, you will want to chmod +x it (make it executable), and add the directory to PATH (like environmental variables on Windows, actually, not like, same thing!)
Now you can use it in shell to ./run it just like any other executable... or one of three things...
bind the script directly to a hotkey with xbindkey
or, create an alias including it, so you can add options, (and optionally bind the alias to hotkey)
or, write a function in bashrc to use it conditionally, creating an automagic workflow that will blow people away.
Basic description of mentioned tools/programs, probably cut&paste from the given URL
xbindkeys is a program that allows you to launch shell commands with your keyboard or your mouse under X Window. It links commands to keys or mouse buttons, using a configuration file. It's independant of the window manager and can capture all keyboard keys.
There are a handful of other similar tools with additional features, such as CLFSWM, but this has been more than sufficiant in my use!
wmctrl (allows for control of GUI windows from CL);
other useful tools that can be used within your scripts,
zenity (creates simple dialogs that interact graphically with the user);
xclip (command line interface to X selections (clipboard));
Devil's Pie (can be configured to detect windows as they are created, and match the window to a set of rules. If the window matches the rules, it can perform a series of actions on that window.);
Xnee (can record, replay and distribute user actions under the X11 environment. Think of it as a robot that can imitate the job you just did. Super powerful for macro-creation! Now that I think of it, xnee can be used for GUI manipulation easily, I've just never used it all that much, as I'm a keyboard junkie.);
x2x (Quite different from others I'm listing, but just as useful if you have multiple systems, it allows you to use your keyboard and mouse to control other computers over SSH. There are plenty of other tools that allow this, but with it I can use all my automation scripts/aliases/commands from PC1 to control PC2, without having to set-up said scripts on the remote PC! Something I can't think of a way to replicate with AHK.);
Not to mention the countless core-utilities built into *nix that can be used. Here are a handful pertaining to GUI that may be useful.
xdpyinfo (display information utility for X, data pulled here can be used in conjunction with other commands, ie. if %data_from_xdpyinfo% = this, then do/don't do this! Obviously this isn't proper syntax, but I'm trying to be layman here! This technique can be used with any other command/program that relays data);
xprop (xprop - property displayer for X, again, can be easily used in conjunction with other commands, to dictate proper circumstance for automation);
xwininfo (xwininfo − window information utility for X, y'all get the drift )
xlsclients (xlsclients - a utility for listing information about the client applications running on a display.);
So really, the possibilities are endless for automation here... This isn't even a fraction of utilities that aid in such a thing. Obviously the difference between utilizing shell for automation and AHK is abstraction, AHK does a good job of making many automations a breeze, but so do many utilities on linux/unix/Mac OSX.
So, while we don't have something like AHK (I'll be honest, when I first looked at it last week, I thought it was nifty for n00bz, but I had no use for it... but after thinking it over, I mean, just look how many tools it can, at least in a way, replicate function of), we do have many ways to create very powerful scripts and utilize them for automation. This is less of a guide and more of an introduction, it would take me a very long time to tell you what each command does, when and where to use it. That's up to you, and whether you are willing to put in the work.
If you're a linux veteran, you may be reading, screaming DUH at the screen, but we all start somewhere. Albeit learning to utilize the *nix Shell, in whatever flavor you decide (go bash or zsh), will make you a better person. Kidding, but it sure makes things interesting! And if you are at all interested in programming languages, this will help immensely in teaching you the basics.
I'm very sure, considering how diverse the linux world is, that there are other tools, and better ways to do so, I LOVE learning about new, useful tools, let me, as well as others here, know what you use!