how to create a script/phrase without having to restart Autokey?

68 views
Skip to first unread message

Ciro Santilli

unread,
May 12, 2012, 9:24:52 AM5/12/12
to autoke...@googlegroups.com
Hi,

As motivated by my previous post, I want to create scripts and phrases without restarting Autokey.

I have tried to copy the code of Engine.create_abbreviation().

The difference is that I have to Quit (Control Q) and restart Autokey, otherwise it crashes is I try to use the phrases I created.

Even better still, would it be possible to make the new item appear without even closing the GUI?

My function:

# test_import.py
def _create_test_item(self, engine, folder):
    p = model.Phrase("asdf", 'asdf')
    p.modes.append(model.TriggerMode.ABBREVIATION)
    p.abbreviation = 'abr'
    folder.add_item(p)
    engine.configManager.config_altered()

Script:

import test_import

test_import.create_test_item(engine, engine.get_folder('gen'))

Error:

Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/autokey/service.py", line 403, in execute
    exec script.code in self.scope
  File "<string>", line 1, in <module>
  File "/home/ciro/backup/noshare/programs/python/autokey/test_import.py", line 5, in <module>
    import model
  File "/usr/share/pyshared/autokey/model.py", line 19, in <module>
    from configmanager import *
  File "/usr/share/pyshared/autokey/configmanager.py", line 798, in <module>
    class GlobalHotkey(AbstractHotkey):
NameError: name 'AbstractHotkey' is not defined

Chris D

unread,
May 14, 2012, 10:16:54 PM5/14/12
to autoke...@googlegroups.com
Yeah that looks very messy... the correct/best way to do this would be to add a method to the engine object that does the necessary magic. Importing AutoKey's internal APIs from your scripts is asking for trouble :)

Chris D

unread,
May 15, 2012, 7:15:15 AM5/15/12
to autoke...@googlegroups.com
My suggestion would be to extend scripting.py with the functionality you want by looking at the existing code for examples. I'm happy to accept patches if you do this.
Reply all
Reply to author
Forward
0 new messages