![]()
Autokey, covered previously on Make Tech Easier, is a superb place to store commonly-used text. But one of Autokey’s more advanced features could be the ability to script it to perform other things. We’ll have a look at two solutions to tap Autokey for advanced desktop scripting.
Note: While the below script done both 12.10 and 13.04 while using the “autokey-qt” flavor, there appears to be some issues with the “autokey-gtk” version within the standard repositories. If you’re using regular (Unity-based) Ubuntu, you should look at installing in the PPA, containing a newer version of Autokey.
Autokey Scripting Basics
Autokey scripting is completed in Python, a trendy programming language employed in everything from Ubuntu’s Ubiquity installer to Google Maps. While you can perform some useful things with only the functions specific to Autokey, you may also use Autokey features generally Python programs to complete just about anything you desire.
The Autokey Wiki contains some useful topics like Installation and FAQ’s. The API Reference, hidden like a link on top of the Sample Scripts page, is how the good stuff is. Looking around the page:
1. At the top with the page are common the methods, or functions, of the current module you’re looking at which are explained in greater detail below.
2. In the left hand column is the return type, or what you get back the use of that method.
3. In the more descriptive listing for each and every method, you’ll hold the method name listed again.
4. Next towards the name, in parentheses, will be the arguments, or even the things you need to supply the method in order for it to complete its job.
5. Lastly, there’s an illustration of this usage for the method.
![]()

Take serious amounts of look through the API reference – you won’t get far with out them. The following is a walk-through of the creation of a script from beginning to end.
Creating an Autokey Script
Autokey scripting is incredibly much like shell scripting, in that you build them one line at any given time, using variables and processes (or in this case methods) to have the desired result. In my case, I want to be capable of highlight some text and stash it away in a text declare later. The first step is always to create a new script in Autokey… you are able to do this by right-clicking on one in the folders and selecting “New Script,” as shown below.
![]()

Give it an identity, then this empty text area to the right is all yours – this is how you’ll enter in the script. In this situation, let’s look at what we want to do step-by-step:
Getting the Currently-Selected Text
Autokey is about automation, so tthere shouldn't be reason for us to copy this text, towards the clipboard or else. We want to hit the hotkey and go, having the text is safely saved for later. Fortunately, the API Reference shows there’s an approach just for this: the QtClipboard method. The following distinctive line of code will grab the currently-selected text for individuals, just as if we’d done an “Edit & Copy” or Ctrl-C ourselves. Instead in the system’s clipboard, we’ll store this in the variable “notecontent”:
notecontent = clipboard.get_selection()
Designating the Full Path to the File
Next, we would like to store this somewhere. We’ll should designate an area for it. Let’s put in a line that shows the folder you want to use, assigned towards the variable “notepath”:
notecontent = clipboard.get_selection()
notepath = "/home/aaron/clips/"
For the file name, I’d want to include a starting time and date stamp of when it was captured. A little Googling reveals there’s a function in Python’s “time” module that can give me the actual date, in YYYY-MM-DD-HH-mm-ss format on command, which we’ll match the prefix “note” along with the suffix “.txt” and assign towards the variable “notename.” We’ll have to importthe time module so we can use it (the truth is, we need this anyway, as forums recommend adding the next line in order to avoid conflicts relating to the script and also the keyboard/mouse). This makes the script look like this:
import time
time.sleep(0.25)
notecontent = clipboard.get_selection()
notepath = "/home/aaron/clips/"
notename = "note" + timestrftime("%Y%m%d%H%M%S") + ".txt"
Creating the File
This is fairly easy to follow:
- Import the time module
- Get the present selection, assign to “notecontent”
- Assign the target directory to “notepath”
- Assign the writing “note,” then your current date/time, as well as “.txt” on the variable “notename.”
All we need to perform now is actually make the file. Fortunately, Autokey provides a way for that too, in the System module:
import time
time.sleep(0.25)
notecontent = clipboard.get_selection()
notepath = "/home/aaron/clips/"
notename = "note" + timestrftime("%Y%m%d%H%M%S") + ".txt"
system.create_file(notepath + notename, content = notecontent)
That’s it! Assign a hotkey, copy some text, to see what happens. With the key functions Autokey provides you, and some Google prowess, you may use Autokey for advanced desktop scripting.
1. Selecting the words
![]()

2. Hit the hotkey, along with a new text file appears
![]()

3. And there’s our selected text, shown inside the less output from the text file.
![]()

What other uses do you use the Autokey for?











In this digital age, almost everything is being become paperless transactions. Travel documents, bank statements, and even bills can now be sent out in digital form, mostly through e-mail. Signing documents are no exception, and there are a number of handy web and mobile apps that allow a user to simply digitize their signatures and fix it towards the document.







