Home > python > Automate tasks with AutoKey

Automate tasks with AutoKey

AutoKey is a desktop automation utility for Linux and X11. It allows you to create scripts and assign hotkeys to these scripts, allowing you to execute them on demand in whatever program you are using.” (source)

I’ve already done similar automatizations with autopy, which is not difficult, but life is much easier with AutoKey. AutoKey is a framework for these kinds of scripts and the great news is you can program it with Python!


sudo apt-get install autokey-qt

There is an “autokey-gtk” version too but I had some problems with that. For me “autokey-qt” worked better.


Use Case
Now let’s see a concrete use case. Printing at my workplace is a bit painful. If I want to send jobs to a powerful printer here, I need to authenticate myself each time (see the figure; click for a larger image). Or, I can use another (shitty) printer…


I must provide my username / password, then click on the OK button. If I print a large document, it’s OK, but if I want to print several small files, it becomes a pain in the ass.

And here is where AutoKey comes to the rescue. I made a simple script that automates this task (click to enlarge):

There is a hotkey associated to this script: CTRL+F1. There is also a window filter, thus it cannot be activated by accident in a wrong environment.

The script is here:

with open(".../print.txt") as f:
    username = f.readline().rstrip("\n")
    password = f.readline().rstrip("\n")

for _ in range(3):

Update (20141102, Manjaro)
I installed Manjaro on one of my laptops. Here are my notes for Autokey.

I had to install it from source, I didn’t find it in the official repositories. After unpacking the archive, I installed it:

sudo python2 setup.py install --record files.txt

The part “--record files.txt” is optional. With Python 3 it didn’t work. I also had to install some additional packages:

sudo pacman -S gtksourceview3 libappindicator-gtk3

Also, there was a problem with filesystem monitoring. Here is the fix:

# edit this file:
$ sudo vim /etc/sysctl.d/99-sysctl.conf
# by adding this line:
fs.inotify.max_user_watches = 100000
# reload the kernel parameters:
$ sudo sysctl --system

Under Manjaro I had luck with “autokey-gtk” (instead of “autokey-qt“).

  1. June 15, 2014 at 18:37

    hi,, i need your help.
    i want to use “enter” for change application (Alt + Tab). What should i do with my auto key?
    i try use script: keyboard.send_keys(“+”), with hotkey: enter, but not successfully.
    thanks a lot

  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: