autokey / autokey

AutoKey, a desktop automation utility for Linux and X11.
https://autokey.github.io/index.html
GNU General Public License v3.0
3.45k stars 191 forks source link

get_triggered_abbreviation() Not Working #948

Open andonagio opened 4 months ago

andonagio commented 4 months ago

AutoKey is a Xorg application and will not function in a Wayland session. Do you use Xorg (X11) or Wayland?

Xorg

Has this issue already been reported?

Is this a question rather than an issue?

What type of issue is this?

None

Choose one or more terms that describe this issue:

Other terms that describe this issue if not provided above:

No response

Which Linux distribution did you use?

Xubuntu 22.04

Which AutoKey GUI did you use?

GTK

Which AutoKey version did you use?

0.96.0

How did you install AutoKey?

*.deb package

Can you briefly describe the issue?

I was working on an Autokey script and ran into trouble trying to use engine.get_triggered_abbreviation(), since I couldn't get any data out of either part of the tuple that it returns. So I created a simple script with just the following line of code and ran Autokey in verbose mode.

abbreviation, trigger_character = engine.get_triggered_abbreviation()

When I opened the text editor, typed my abbreviation, and hit enter, what I saw was the following:

DEBUG - autokey.service - Triggered a Script by an abbreviation. 
Setting it for engine.get_triggered_abbreviation(). abbreviation='', trigger=''

To sanity-check myself, I then added this second line to my script:

print("abbreviation is" + abbreviation)

Sure enough, in the terminal, I get

DEBUG - autokey.service - Triggered a Script by an abbreviation.
Setting it for engine.get_triggered_abbreviation(). abbreviation='', trigger=''
abbreviation is 

It doesn't appear that abbreviation and trigger are getting set. In the Set Abbreviations window, I have all of the boxes unchecked except "Omit Trigger Character". That might explain why trigger_character is not set, but why can't I get the triggered abbreviation?

Can the issue be reproduced?

Always

What are the steps to reproduce the issue?

  1. Create a script that contains the line 'abbreviation, trigger_character = engine.get_triggered_abbreviation()`
  2. Assign an abbreviation to that script
  3. Run Autokey in verbose mode
  4. Open a text editor, type in the abbreviation, and hit enter
  5. Note the output in the terminal

What should have happened?

The "abbreviation" variable should have stored the abbreviation I used for the phrase expansion.

What actually happened?

The "abbreviation" variable is empty

Do you have screenshots?

No response

Can you provide the output of the AutoKey command?

DEBUG - autokey.service - Triggered a Script by an abbreviation. 
Setting it for engine.get_triggered_abbreviation(). abbreviation='', trigger=''

Anything else?

No response

josephj11 commented 4 months ago

I will try to recreate this, but it might be a while.

In the mean time, you can fake it for the most common case.

Start your script by typing Ctrl+shift+left. In many applications, this will select the word to the left which just happens to be the abbreviation that triggered the script. Then, call clipboard.get_selection() to get the selection into a variable. Don't set Remove typed abbreviation. That text is still selected, so it will get removed when the script emits some text unless you start by emitting something that deselects it first.

This doesn't work for all the triggering settings and applications, but it's a lot better than nothing.

andonagio commented 4 months ago

I can work around it, but having access to that function saves me a step in my script. Thank you for looking into it.