Scripting - autokey/autokey GitHub Wiki

Contents

Introduction

AutoKey scripts accept most Python code. AutoKey also offers some custom API functions that can be used in scripts. For specific details on the custom functions available to AutoKey scripts, see the API reference.

Example scripts

You can find several pages of example scripts and user-contributed scripts on the Example Scripts page as a demonstration of some of the basic and advanced capabilities of AutoKey's scripting service.

Contributing scripts

Feel free to use the scripts for your own purposes. However, if you significantly modify them or come up with something new as a result of using them, please post them in one of our community platforms so one of the wiki moderators can add them here for all to benefit.

All submitted scripts are publicly licensed as GNU GPL v3

Porting your scripts from Python 2 to Python 3

  • Changes were made to source code to keep the scripting API stable. The system.exec_command() returns a string. But if you use functions from the standard library, you will have to fix that, as your script runs on a Python 3 interpreter. For example, expect subprocess.check_output() to return a bytes object.
  • The 2to3 Python program can be used to automatically translate your source code from Python 2 to Python 3.
  • Some guides on porting code to Python 3:

Renaming scripts

Rename a script in AutoKey

  1. Open AutoKey's main window.
  2. Click the greater-than symbol next to your Sample Scripts directory.
  3. Browse to the script you'd like to rename.
  4. Right-click its name.
  5. Choose Rename from the context menu.
  6. Type in the new name.
  7. Make sure that the Update name on file system box has a check-mark in it (it's checked by default).
  8. Click the OK button.

Rename a script in your file manager

  1. Open your file manager.
  2. Open the ~/.config/autokey/data/Sample Scripts directory.
  3. Find the .json and .py files for your script.
  4. Edit the name of its .py file.
  5. Edit the name of its .json file.
  6. Open its .json file in a text editor.
  7. Edit its name in the description field.
  8. Save the change.
  9. Shut down AutoKey.
  10. Restart AutoKey.