Start a new topic

Using Autokey

This posting is in reponse to a request from user:idim in this thread here about AutoKey in Linux.

See also this thread on AutoKey.


AutoKey is a Linux equivalent of Windows' autohotkey (which I'm not personally familiar with), but it uses Python as a scripting language, making it extremely powerful and flexible.

There are two versions: AutoKey, which uses python 2 and autokey-py3, which uses Python 3. As I understand it, the former is no being developed or supported, the latter is still active.


I use AutoKey extensively for various usefully automatable tasks, but user:idim was particularly interested in using it for search.


There are lots of sample scripts out there, see for example here and here, the latter being the original source for my various search scripts.


I'll post here one of my basic search scripts, based as noted on code from the second of the above links. It does a Google search on the europa.eu domain (site:europa.eu). Note that I am (I think!) using the python 2 version:

 

import webbrowser
base="http://www.google.com/search?q="
phrase=clipboard.get_selection()

#Remove trailing or leading white space and find if there are multiple
#words.
phrase=phrase.strip()
singleWord=False
if phrase.find(' ')<0:
    singleWord=True

#Generate search URL.
if singleWord:
    search_url=base+phrase+"+site:europa.eu"

if (not singleWord):
    phrase='+'.join(phrase.split())
    search_url=base+phrase+"+site:europa.eu"
      
webbrowser.open_new_tab(search_url)
As you'll see, it's extremely simple and very easy to customise for other sites (as long as they support search terms embedded in the URL). I have scripts for searching Linguee, IATE, for ICD10 codes on who.int, thesaurus.com and LEO.

I also have scripts for converting dd.mm.yyyy dates to month dd, yyyy formated dates and scripts for converting German legal citations to an English format, which I'd be happy to share if anyone is interested, and a few little functions for various non-translation work processes (such as writing certain more or less standard emails).

If there's anything else you want to know, post here, and I'll do my best to answer.

Jeremy



1 Comment

Hello Jeremy,


Many thanks for this post. Just tested the script and it works just fine on my AutoKey-py3.


It is a very nice platform-wide solution for quickly launching various web searches based on clipboard content.


I remember the page on AutoKey sample scripts, but had missed the Google groups page.


Cheers,


Jean

Login to post a comment