|
SampleScripts
Sample AutoKey Scripts.
Featured IntroductionThis 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. ScriptsDisplay Active Window InformationDisplays 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/TimeThis 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 MenuThis 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 SelectionThis 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 ValueThis 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 abbreviationThis 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 phraseThis 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)
|
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.
Is it possible to control the mouse?
@mailryan: yes, see full documentation: http://autokey.sourceforge.net/apidoc/lib.scripting.Mouse-class.html
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
clipboard.get_selection only appears to work with ASCII characters. I get the ominous UnicodeEncodeError? when there are accented characters in the selection.
>> 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".
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
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...
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.
> @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
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.
How do you use a for loop