running autokey scripts from terminal

1,804 views
Skip to first unread message

Dave

unread,
Dec 30, 2011, 2:25:30 PM12/30/11
to autokey-users
Now that autokey has separate script files instead of one big file
that contains everything, is there a way to trigger a script from a
bash script?

I tried the following:
autokey "path/to/script"
autokey-gtk "path/to/script"

and both just opened the config window

and this:
python "path/to/script"

gave an error:
david@david-Dell-DXP051:~$ python "/home/david/.config/autokey/data/
Daves misc/open healthquest.py"
Traceback (most recent call last):
File "/home/david/.config/autokey/data/Daves misc/open
healthquest.py", line 2, in <module>
if window.wait_for_exist(".*healthquest2.*", timeOut=1):
NameError: name 'window' is not defined

presumably because autokey scripts contain non-generic python bits, or
is there a way to make them work in this way?

Thanks,
Dave

Chris D

unread,
Jan 1, 2012, 5:06:05 PM1/1/12
to autokey-users
You can do this with the autokey-run command. Type man autokey-run to
get help on how to use it.

Dave

unread,
Jan 2, 2012, 12:30:07 PM1/2/12
to autokey-users
thanks Chris,

Here's what I'm getting so far (tried with and without quotes around
the script name)

david@linux-laptop:~$ autokey-run -s /home/david/.config/autokey/data/
Daves misc/open a file/open zim.py
org.freedesktop.DBus.Python.Exception: Traceback (most recent call
last):
File "/usr/lib/pymodules/python2.6/dbus/service.py", line 702, in
_message_cb
retval = candidate_method(self, *args, **keywords)
File "/usr/lib/python2.6/dist-packages/autokey/gtkapp.py", line 325,
in run_script
self.app.service.run_script(name)
File "/usr/lib/python2.6/dist-packages/autokey/service.py", line
218, in run_script
script = self.__findItem(name, model.Script, "script")
File "/usr/lib/python2.6/dist-packages/autokey/service.py", line
226, in __findItem
raise Exception("No %s found with name '%s'" % (typeDescription,
name))
Exception: No script found with name '/home/david/.config/autokey/data/
Daves'

david@linux-laptop:~$ autokey-run -s '/home/david/.config/autokey/data/
Daves misc/open a file/open zim.py'
org.freedesktop.DBus.Python.Exception: Traceback (most recent call
last):
File "/usr/lib/pymodules/python2.6/dbus/service.py", line 702, in
_message_cb
retval = candidate_method(self, *args, **keywords)
File "/usr/lib/python2.6/dist-packages/autokey/gtkapp.py", line 325,
in run_script
self.app.service.run_script(name)
File "/usr/lib/python2.6/dist-packages/autokey/service.py", line
218, in run_script
script = self.__findItem(name, model.Script, "script")
File "/usr/lib/python2.6/dist-packages/autokey/service.py", line
226, in __findItem
raise Exception("No %s found with name '%s'" % (typeDescription,
name))
Exception: No script found with name '/home/david/.config/autokey/data/
Daves misc/open a file/open zim.py'


I also tried it with just the script name with and without quotes same
error

Joe

unread,
Jan 2, 2012, 2:25:21 PM1/2/12
to autoke...@googlegroups.com
Don't know how to fix this, but ...
1) Without the quotes (first attempt), AutoKey doesn't get passed the
name of your script because of the way bash splits arguments on blanks.

2) Might not help, but could you try:
a) Create an identical script from within AutoKey, but named "myscript"
(no blanks in name)
b) Try it using a hotkey, etc. to make sure it runs.
c) cd '/home/david/.config/autokey/data/Daves misc/open a file/'
(change to the directory where the new script was saved)
d) autokey-run -s myscript

This will test the process without any blanks in path names anywhere to
cause problems. This might not be what's causing the problem, but it
would be good to eliminate it this way just to be sure.

Blanks in path names are allowed in Linux, but they can cause all sorts
of problems for bash scripts (or things entered on the command line) if
the scripts are not coded carefully to handle them.

Joe

Chris D

unread,
Jan 2, 2012, 4:16:37 PM1/2/12
to autokey-users
The manual page specifies that you pass the *name* of the script/
phrase/folder, not the path to it. By that it means the name as it
appears in the AutoKey main window.

Dave Parker

unread,
Jan 2, 2012, 4:36:54 PM1/2/12
to autoke...@googlegroups.com

Well that's straight forward (and too easy - I was stuck in the mind set of thinning about the files)  - nice feature!

Thanks,
Dave

Rammedisoft

unread,
Aug 29, 2012, 5:52:17 AM8/29/12
to autoke...@googlegroups.com
Congrats Dave for getting the problem solved easily.

But on my terminal window in ubuntu 10.04 LTS, on trying to run a script named terminal2 created with autokey (GTK UI) 0.61.7
with the command autokey-run -s terminal2 it is showing
autokey-run command not found

I tried to get the manual etc., it is of no use.

Please help

Srikant

unread,
Aug 30, 2012, 2:14:37 AM8/30/12
to autoke...@googlegroups.com
Hello Dave and fellows,
I too have the same problem. I want to know more about your approach.
I'm using autokey-run -s Insert\ Date.py as per this thread, I also tried all other possible ways to feed paths,
but error is same:

srikant ~/.config/autokey/data $ autokey-run -s Insert\ Date.py

org.freedesktop.DBus.Python.Exception: Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/dbus/service.py", line 707, in _message_cb

    retval = candidate_method(self, *args, **keywords)
  File "/usr/lib/python2.7/dist-packages/autokey/common.py", line 60, in run_script
    self.app.service.run_script(name)
  File "/usr/lib/python2.7/dist-packages/autokey/service.py", line 223, in run_script

    script = self.__findItem(name, model.Script, "script")
  File "/usr/lib/python2.7/dist-packages/autokey/service.py", line 231, in __findItem

    raise Exception("No %s found with name '%s'" % (typeDescription, name))
Exception: No script found with name 'Insert Date.py

Thanks in advance.
Srikant


On Tuesday, January 3, 2012 3:06:54 AM UTC+5:30, Dave wrote:

Alvin Mites

unread,
Nov 15, 2012, 10:56:59 PM11/15/12
to autoke...@googlegroups.com, u.srikan...@gmail.com
old thread but it's an issue I ran into 

the trick that worked for me is to pass the name of the script without the extension or path

ie: my script is named SCRIPT.py

so I would enter at prompt

     autokey-run -s SCRIPT

this file exists within a user defined scripts folder, can see some caveats to this but so long as you keep your scripts with unique names shouldn't be an issue
Reply all
Reply to author
Forward
0 new messages