Replicating AutoHotKey's magic on a linux/unix/mac osx computer (thoughts on linux/osx port?)

Discuss other useful utilities, general computing tips & tricks, Internet resources, etc.
M0doJ
Posts: 15
Joined: 09 Oct 2015, 07:31

Replicating AutoHotKey's magic on a linux/unix/mac osx computer (thoughts on linux/osx port?)

13 Oct 2015, 23:27

Replicating AutoHotKey's magic on a linux/unix/mac osx computer (thoughts on linux/osx port?)

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. :P

###########################################################################################################################

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 :P 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 :P

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 :P

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 :P)

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!
M0doJ
Posts: 15
Joined: 09 Oct 2015, 07:31

Re: Replicating AutoHotKey's magic on a linux/unix/mac osx computer (thoughts on linux/osx port?)

13 Oct 2015, 23:46

Okay! So it looks like there have been a couple attempts to tackle this

First, Polyethen's ( I hear he's quite infamous here!) IronAHK
http://www.autohotkey.com/board/topic/3 ... linux-mac/

and

AutoKey
https://code.google.com/p/autokey/

I'll look into both and decide whether it's worth / or if I can / I'm allowed, to contribute. From my WHOLE 3 MINUTES OF PERUSING, it looks like IronAHK is C#... why?! Hah, I don't mind, honestly. I can work with C# fine, it's the elitist-linux world who refuse anything Mono. I don't want to turn anyone off to good software... but now that I think about it, how likely is it that someone using it would be one of those language-snobs in the first place? Minimal.

( I should state, it has less to do with the actual language than it does with it's creator, Microsoft, and that it's in a sense, not "free and open", but that's a can of worms I don't want to get into)
User avatar
tank
Posts: 3122
Joined: 28 Sep 2013, 22:15
Location: CarrolltonTX
Contact:

Re: Replicating AutoHotKey's magic on a linux/unix/mac osx computer (thoughts on linux/osx port?)

14 Oct 2015, 09:48

I am a mostly nix user. but i dont have this kind of time. you found the only 2 references i would have pointed you too. Poly mysteriously gave up on his IronAHK project no idea why. but it did and does have its fanfair. i would love to see someone pick it even without COM integration it would be a super valiuable asset. there are many more nix users in this community than you might imagine. there would be alot of support if you could get this going
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter
geek
Posts: 1051
Joined: 02 Oct 2013, 22:13
Location: GeekDude
Contact:

Re: Replicating AutoHotKey's magic on a linux/unix/mac osx computer (thoughts on linux/osx port?)

14 Oct 2015, 09:54

I've started work on a python library that should let you do most of the things in AutoHotkey in python (under many Linux distros). I'm basing my code off of AutoKey as it seems to have most of this stuff already figured out. I honestly haven't gotten much further than poking around in the source for AutoKey, but I plan on letting the user be able to do things like define hotkeys (and hotstrings) via decorator.

Code: Select all

@hotkey("^5")
def MyFunc():
   send("hello world!")
User avatar
tank
Posts: 3122
Joined: 28 Sep 2013, 22:15
Location: CarrolltonTX
Contact:

Re: Replicating AutoHotKey's magic on a linux/unix/mac osx computer (thoughts on linux/osx port?)

14 Oct 2015, 10:19

Pythons strictness may alienate the sensibilities of autohotkey users. i wonder if perl wouldnt be a more suitable choice for this kind of userbase. either probably wouldnt actually consitute "Porting" of ahk. I am unsure if your intending on duplicating ahk functionality or making something that would support at least most basic ahk scripts as-is
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter
M0doJ
Posts: 15
Joined: 09 Oct 2015, 07:31

Re: Replicating AutoHotKey's magic on a linux/unix/mac osx computer (thoughts on linux/osx port?)

14 Oct 2015, 13:23

tank wrote:Pythons strictness may alienate the sensibilities of autohotkey users. i wonder if perl wouldnt be a more suitable choice for this kind of userbase. either probably wouldnt actually consitute "Porting" of ahk. I am unsure if your intending on duplicating ahk functionality or making something that would support at least most basic ahk scripts as-is
This is what I was questioned with, whether a simple ahk to python converter was sufficient, or if a port was needed. I'd like it to maintain functionality with existing ahk scripts as is, as that's the only way to make it truly useful.
geek
Posts: 1051
Joined: 02 Oct 2013, 22:13
Location: GeekDude
Contact:

Re: Replicating AutoHotKey's magic on a linux/unix/mac osx computer (thoughts on linux/osx port?)

14 Oct 2015, 23:34

I intend to "duplicate functionality" as you put it.

AutoHotkey, as great as it is, wouldn't really "fit" with unixy systems how it is now. Rebuilding a sufficiently similar system from the ground up to be compatible would be better I think. Most of the even marginally complex scripts here just don't fit the paradigms and interfaces of other systems. Supposing I did manage to get something to run AHK scripts (like IronAHK) it'd be an exercise in pointless as most scripts still wouldn't run (unless I built this with WINE I suppose, though that brings its own host of issues).

In contrast, python was built from the ground up to be cross platform. Existing code written for python is mostly already written to handle the issues that arise from the differences in operating systems. You won't have to worry about it choking on different newline types or case sensitive file systems, or any of those kinds of issues. AutoHotkey scripts just weren't written with this kind of flexibility in mind and it would be a nightmare to try to make them work. A non-insignificant number of scripts floating around still don't work with 64 bit, and that's been around for years.

There's no need to reinvent any wheels, as python already has excellent replacements for most of the things built into AHK. GDI+ can be replaced with PIL. Gui commands can be replaced by a host of solutions such as QT, GTK, TK, and so on. The only thing python is really missing from a library standpoint is a good cross platform DE interface library, which is what I intend to write. AutoKey is a great starting point, but it appears to be built as a graphical wrapper around a series of separate python scripts you write via its interface. Because of how this forces you to use their structure, it becomes very difficult to use it from your own code. After I strip all that out and rewrite it to make sense as a library (or at least write something similar using it as reference) we'd be pretty well off I think.
User avatar
joedf
Posts: 8937
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Replicating AutoHotKey's magic on a linux/unix/mac osx computer (thoughts on linux/osx port?)

15 Oct 2015, 10:22

Well, either way, something cross platform similar to AutoHotkey is always welcome :+1:
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
mikek
Posts: 11
Joined: 30 Sep 2013, 17:17

Re: Replicating AutoHotKey's magic on a linux/unix/mac osx computer (thoughts on linux/osx port?)

15 Oct 2015, 16:34

About two years ago I purchased a Raspberry Pi in order to run automated tasks. I like it's small size and low electrical use, and cheap price. Since taking an initial look, I have not used it because of the time involved learning how to do things I already know how to do on Windows. I am wondering if a project such as what is being considered here could be especially valuable if able to run on a Raspberry Pi.

- Mike
Guest

Re: Replicating AutoHotKey's magic on a linux/unix/mac osx computer (thoughts on linux/osx port?)

20 Mar 2016, 09:05

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
2014 I switched to Ubuntu at work and home. At that time, those utilities had not been updated since 2009, and usually did not work as advertised. Even the basic tutorials wouldn't run. If those tools get updated, then I'd agree they'd match the functionality of AHK.

I'd like to see something for Mac too. Actually, I'd prefer to see every one ditch Mac and jump on Ubuntu.
epse
Posts: 1
Joined: 19 Jun 2016, 11:21
Contact:

Re: Replicating AutoHotKey's magic on a linux/unix/mac osx computer (thoughts on linux/osx port?)

19 Jun 2016, 11:25

Can you trigger a shell script on a keystroke in linux? Been doing stuff with keycombo's for a while now, but autokey (which used to be able to do text expansion) has not been updated in a while and still depends on a no longer existent python library.
geek
Posts: 1051
Joined: 02 Oct 2013, 22:13
Location: GeekDude
Contact:

Re: Replicating AutoHotKey's magic on a linux/unix/mac osx computer (thoughts on linux/osx port?)

19 Jun 2016, 11:28

I know in XFCE there's an "Application Shortcuts" hotkey configuration section in the keyboard settings.
Guest

Re: Replicating AutoHotKey's magic on a linux/unix/mac osx computer (thoughts on linux/osx port?)

19 Jun 2016, 13:28

GeekDude wrote:I know in XFCE there's an "Application Shortcuts" hotkey configuration section in the keyboard settings.
Yeah, but again, those are key combo's, not keystrokes (like for text expansion) :(
bob

Re: Replicating AutoHotKey's magic on a linux/unix/mac osx computer (thoughts on linux/osx port?)

19 Jun 2016, 22:48

After all these years, still can't move to Linux because no port of autohotkey, you'd think somebody would have gotten to it by now. But just like this page, a lot of hot air and absolutely nothing useful.
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Replicating AutoHotKey's magic on a linux/unix/mac osx computer (thoughts on linux/osx port?)

20 Jun 2016, 04:13

That's because you can't port it easily.
You can go ahead and create it.
Couldn't be rocket science could it?
At least you sure don't make it seem that way.
Recommends AHK Studio
Sjeiky
Posts: 1
Joined: 03 Jul 2016, 19:28

Re: Replicating AutoHotKey's magic on a linux/unix/mac osx computer (thoughts on linux/osx port?)

03 Jul 2016, 19:57

Well I found out AutoKey worked on Ubuntu 16.04. I´m a Windows 7 nerd :geek: and had a lot of AutoHotKey scripts running on Windows 7, but with time ticking :crazy: that Microsoft Corporation stops supporting Windows 7 in 2020 :x , I had to swap to Ubuntu (because I h8 Windows 8 and 10 :sick: ). I use key board bindings (System Settings -> Keyboard -> Shortcuts -> Add custom shortcut) to automate tasks in Linux and Autokey (installed from Ubuntu Software Center) for text expansion aka hotstrings (My Phrases -> Set Abbreviations -> Tringger on: All non-word -> Check: Remove typed abbreviation and Omit trigger character -> Uncheck: All others -> Add -> type hotstring -> press enter -> Enjoy text expansion on terminal, browser and editors).
HBinswanger
Posts: 17
Joined: 14 Feb 2016, 00:45

Re: Replicating AutoHotKey's magic on a linux/unix/mac osx computer (thoughts on linux/osx port?)

15 Oct 2016, 10:12

Getting AHK or AHK-lookalike for OS X is very important to both me and my wife. Has there been any progress?
User avatar
tank
Posts: 3122
Joined: 28 Sep 2013, 22:15
Location: CarrolltonTX
Contact:

Re: Replicating AutoHotKey's magic on a linux/unix/mac osx computer (thoughts on linux/osx port?)

18 Oct 2016, 17:11

No, as a matter of fact there is no initiative to port to other OS. Much of what AHK is wrappers of Windows API. AHK is open source. While porting it isnt really even an option for the reason i just mentioned its entirely possible for someone to model a brand new application with similar functionality
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter
User avatar
joedf
Posts: 8937
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Replicating AutoHotKey's magic on a linux/unix/mac osx computer (thoughts on linux/osx port?)

18 Oct 2016, 21:48

For me personally, I just what the terribly flexible syntax haha :lol:
So I can just concentrate on getting the job done.
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
NTKO

Re: Replicating AutoHotKey's magic on a linux/unix/mac osx computer (thoughts on linux/osx port?)

30 Dec 2016, 04:51

Your best bet at this point is to move over to Python. It's stricter, but has all of the available functionality. It loses a lot of AHK's speed, but is one of the quickest programming languages to write in. There appears to be a Wine entry for it, but I haven't used it.

Return to “Other Utilities & Resources”

Who is online

Users browsing this forum: No registered users and 23 guests