Script to ask for text input and then output that input within a text string

186 views
Skip to first unread message

Josh Welsh

unread,
Nov 18, 2020, 5:46:12 PM11/18/20
to autokey-users

Hi there,
This is probably a pretty basic question, but I have looked high and low and not been able to find an answer. Or it could be that I haven't found an answer I understand. :-)

At any rate, I'd like to use AutoKey to ask me for text input, and then incorporate that input into a phrase that it spits out.  So I'd hit the abbreviation combo, then a dialog would pop up and it would say "Enter the name" and I'd enter it, and then the phrase would be pasted that would say "Nice work on this [The name I entered.] See comments below for more feedback."

Thanks for any suggestions you might have for me!

Josh

Sam Sebastian

unread,
Nov 18, 2020, 6:02:16 PM11/18/20
to autoke...@googlegroups.com
# Enter script code
winTitle = window.get_active_title()
ret, recieved_input = dialog.input_dialog(title="Name", message="Enter name:")
if not ret:
    window.activate(winTitle)
    time.sleep(0.25)
    keyboard.send_keys("Feedback for "+recieved_input)
  
Heres a quick script I whipped up

--
You received this message because you are subscribed to the Google Groups "autokey-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to autokey-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/autokey-users/5c44872c-29a6-446c-b929-fec240d842a8n%40googlegroups.com.

Joe

unread,
Nov 18, 2020, 10:40:11 PM11/18/20
to autoke...@googlegroups.com
Why do you do the window activation?

If the replacement phrase gets much longer or contains any non EN-US
characters, then emit the result using the clipboard API instead of the
keyboard API.

import time

...

clipboard.fill_clipboard("Feedback for "+recieved_input)
time.sleep(0.1)
keyboard.send_keys("<ctrl>+v")

Joe
> <mailto:autokey-user...@googlegroups.com>.
> <https://groups.google.com/d/msgid/autokey-users/5c44872c-29a6-446c-b929-fec240d842a8n%40googlegroups.com?utm_medium=email&utm_source=footer>.
>
> --
> You received this message because you are subscribed to the Google
> Groups "autokey-users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to autokey-user...@googlegroups.com
> <mailto:autokey-user...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/autokey-users/CALutQj6d2XMDd4OGw-cVY6-Un8dYzO_Cxytjgq4MhSfOJGiFMw%40mail.gmail.com
> <https://groups.google.com/d/msgid/autokey-users/CALutQj6d2XMDd4OGw-cVY6-Un8dYzO_Cxytjgq4MhSfOJGiFMw%40mail.gmail.com?utm_medium=email&utm_source=footer>.

Sam Sebastian

unread,
Nov 19, 2020, 11:10:07 AM11/19/20
to autoke...@googlegroups.com
Better safe than sorry, in case you have to click on to another page to reference whatever input. I usually include stuff like that just to be a ironclad script. But yeah either will work.

To unsubscribe from this group and stop receiving emails from it, send an email to autokey-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/autokey-users/0388dc72-8c85-626e-5749-e291e6f00b6c%40main.nc.us.

Josh Welsh

unread,
Nov 19, 2020, 12:48:53 PM11/19/20
to autokey-users

Wow! Thanks so much for the help! 

At the risk of proving that no good deed goes unpunished, I have a follow-up question. When I try to run that script, I get an error. This is the script error I get:

Script name: 'Selection Test'

Traceback (most recent call last):

File "/usr/lib/python3/dist-packages/autokey/service.py", line 485, in execute

exec(script.code, scope)

File "<string>", line 3, in <module>

File "/usr/lib/python3/dist-packages/autokey/scripting.py", line 290, in input_dialog

return self._run_kdialog(title, ["--inputbox", message, default], kwargs)

File "/usr/lib/python3/dist-packages/autokey/scripting.py", line 259, in _run_kdialog

universal_newlines=True) as p:

File "/usr/lib/python3.6/subprocess.py", line 729, in __init__

restore_signals, start_new_session)

File "/usr/lib/python3.6/subprocess.py", line 1364, in _execute_child

raise child_exception_type(errno_num, err_msg, err_filename)

FileNotFoundError: [Errno 2] No such file or directory: 'kdialog': 'kdialog'


This makes me think something is installed wrong in my AutoKey? Any suggestions on how to fix this? 


Thanks so much!

Josh

Sam Sebastian

unread,
Nov 19, 2020, 12:52:26 PM11/19/20
to autoke...@googlegroups.com
You have to have `kdialog` installed if you are using the Qt version and want access to the `dialog` api library. On debian/ubuntu `sudo apt-get install kdialog` works for me.

Josh Welsh

unread,
Nov 19, 2020, 1:37:51 PM11/19/20
to autokey-users
That is amazing! How does it feel to know you just made someone's day, week, month, and probably year about 200% better? 

Thanks so much!

Josh

Sam Sebastian

unread,
Nov 19, 2020, 3:49:25 PM11/19/20
to autoke...@googlegroups.com
Glad we could be of help :)

Little Girl

unread,
Nov 20, 2020, 12:00:21 PM11/20/20
to autokey-users
Hey there,

I hope it's not too late to jump in here. Here's my take on that. Also, my apologies in advance if the code formatting is all messed up below. It looks like Google completely did away with the old editor, so this message is me experimenting with using the "Remove formatting" button and then manually inserting the tabbed indents back in afterwards. In the event that they're messed up, the lines that start with dialog or keyboard should be indented.

This example gives the output as a dialog:

ret, response = dialog.input_dialog(title="Name", message="Type something:")
if ret:
dialog.info_dialog(title='Status', message="You cancelled.", width='200')
else:
dialog.info_dialog(title='Your input was: ', message=response)

This example gives the output as text:

ret, response = dialog.input_dialog(title="Name", message="Type something:")
if ret:
keyboard.send_keys("You cancelled.")
else:
keyboard.send_keys("Your input was: "+response)

Reply all
Reply to author
Forward
0 new messages