My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
SampleScripts  
Sample AutoKey Scripts.
Featured
Updated Feb 4, 2012 by itscoolr...@gmail.com

Introduction

This page contains some very basic script examples to demonstrate the capabilities of AutoKey's scripting service.

For specific details on the custom functions available to AutoKey scripts, see the API reference.

Scripts

Display Active Window Information

Displays the information of the active window after 2 seconds

import time
time.sleep(2)
winTitle = window.get_active_title()
winClass = window.get_active_class()
dialog.info_dialog("Window information", 
          "Active window information:\\nTitle: '%s'\\nClass: '%s'" % (winTitle, winClass))

Insert Current Date/Time

This script uses the simplified system.exec_command() function to execute the Unix date program, get the output, and send it via keyboard output

output = system.exec_command("date")
keyboard.send_keys(output)

List Menu

This script shows a simple list menu, grabs the chosen option and sends it via keyboard output.

choices = ["something", "something else", "a third thing"]

retCode, choice = dialog.list_menu(choices)
if retCode == 0:
    keyboard.send_keys("You chose " + choice)

X Selection

This script grabs the current mouse selection, then erases it, and inserts it again as part of a phrase.

text = clipboard.get_selection()
keyboard.send_key("<delete>")
keyboard.send_keys("The text %s was here previously" % text)

Persistent Value

This script demonstrates 'remembering' a value in the store between separate invocations of the script.

if not store.has_key("runs"):
    # Create the value on the first run of the script
    store.set_value("runs", 1)
else:
    # Otherwise, get the current value and increment it
    cur = store.get_value("runs")
    store.set_value("runs", cur + 1)
    
keyboard.send_keys("I've been run %d times!" % store.get_value("runs"))

Create new abbreviation

This script creates a new phrase with an associated abbreviation from the current contents of the X mouse selection (although you could easily change it to use the clipboard instead by using clipboard.get_clipboard()).

import time
time.sleep(0.25)
# The sleep seems to be necessary to avoid lockups
contents = clipboard.get_selection()
retCode, abbr = dialog.input_dialog("New Abbreviation", "Choose an abbreviation for the new phrase")
if retCode == 0:
    if len(contents) > 20:
        title = contents[0:17] + "..."
    else:
        title = contents
    folder = engine.get_folder("My Phrases")
    engine.create_abbreviation(folder, title, abbr, contents)

Create new phrase

This is similar to the above script, but just creates the phrase without an abbreviation.

import time
time.sleep(0.25)
# The sleep seems to be necessary to avoid lockups
contents = clipboard.get_selection()
if len(contents) > 20:
    title = contents[0:17] + "..."
else:
    title = contents
folder = engine.get_folder("My Phrases")
engine.create_phrase(folder, title, contents)
Comment by inductiv...@gmail.com, Oct 1, 2009

This may seem obvious once you know, but I haven't seen it mentioned anywhere else. In order to turn a Phrase into a Script, choose Edit > Convert to Script. If you don't do this, Autokey will just paste your script's code instead of running it.

Comment by mailr...@gmail.com, Oct 15, 2009

Is it possible to control the mouse?

Comment by m...@paddy-net.com, Jan 5, 2010
Comment by kas...@sfr.fr, Feb 1, 2010

I have the problem mentioned above by inductiveload. However, the option "Convert to Script" is not available under "Edit" (latest autokey loaded into Ubuntu 9.10 with Synaptic). Is there another solution, please? Thanks in advance, kaspin

Comment by alastair...@gmail.com, Feb 6, 2010

clipboard.get_selection only appears to work with ASCII characters. I get the ominous UnicodeEncodeError? when there are accented characters in the selection.

Comment by presov...@gmail.com, Feb 10, 2010

>> option "Convert to Script" is not available under "Edit"

This option is not visible (available) in version 0.54 'shipped' with Ubuntu 9.10. However if you download (see INSTALL) current version 0.61.2, in order to use code as code /and not to be pasted as string/ you can use context menu item "New script".

Comment by cedardoc...@gmail.com, Feb 25, 2010

I'm new to linux but have used autohotkey a lot and am looking for ways to reproduce it to a degree. Could someone please give an example of how to make a keyboard shortcut to open a specific file?

Thanks

Comment by gruener....@gmail.com, Mar 1, 2010

anyone ever encountered the issue that "000d" is appended to every line when handling multiline selections? how do I get rid of that? stripped newlines, manipulated each line and then put the together again with a newline as separation...

Comment by taurol...@gmail.com, Apr 2, 2010

Does autokey have any method of monitoring a keypress? I would like to be able to write a script that when I hold down a hotkey, it will repeat a single keypress every 0.5 seconds. I believe this will also require some sort of LOOP command.

Comment by lars.rei...@gmail.com, Mar 30, 2011

> @mailryan: yes, see full documentation: http://autokey.sourceforge.net/apidoc/lib.scripting.Mouse-class.html

Is it possible to just send mouse buttons without a position? E.g. when I want to use the current position and modify the default clipboard copy / paste behavior?

If it is not possible ATM (since the Mouse class is a bit thin) could you please integrate more mouse control? thanks

Comment by guillerm...@gmail.com, Apr 17, 2011

Is it possible to capture mouse and or keyboard events? i want to move windows holding right click, but resize them if i'm holding ctrl.

Comment by duyhoust...@gmail.com, Aug 9, 2011

How do you use a for loop

Powered by Google Project Hosting