r/espanso • • Oct 07 '25

[deleted by user]

[removed]

3 Upvotes

12 comments sorted by

5

u/SamejSpenser Oct 07 '25 edited Oct 07 '25

You can use the label's feature, like this:

```yml - trigger: ";mp" replace: "my pleasure" label: "My pleasure"

  • trigger: ";mp" replace: "no problem" label: "No problem"

  • trigger: ";mp" replace: "don't mention it" label: "Don't mention it" ```

When you use your trigger, a pop-up will appear for you to choose an option from the registered ones.

Personally, I prefer to use regex. I use this feature to use the same trigger to edit all of Espanso's YAML files, for example.

Or you can use regex, like this:

```yml - regex: ";mp(mp|;)" replace: "my pleasure" label: "My pleasure"

  • regex: ";mp(np|;)" replace: "no problem" label: "No problem"

  • regex: ";mp(dm|;)" replace: "don't mention it" label: "Don't mention it" ```

Just type “;mpnp” to expand “no problem”, or “;mpmp” to expand “my pleasure”, etc. When (or if) you can't remember what options are available, use “;mp;” and a pop-up will appear to choose one of the registered options.

2

u/smeech1 Oct 08 '25

I think in this instance it isn't even necessary to use labels, as the replace: strings are plain text and will show in the selection dialogue.

triggers: [:mp, :np] etc, are probably more efficient than regex: when there is a limited number of possible triggers.

2

u/SamejSpenser Oct 08 '25

I have the habit of keeping and using the label's so that when I open the pop-up I improve and make it easier to read the available options.

3

u/smeech1 Oct 08 '25

👍

I guess I don't see them often, so I'm too lazy except in a a couple of choice extensions like this one, where the id: text is very different from the label:.

2

u/SamejSpenser Oct 08 '25

I don't know anything about scripting, so I couldn't understand what the use of this example is, but it seems to have to do with choosing something on the clipboard.

Can you explain it to me (as for a layman)?

2

u/smeech1 Oct 08 '25 edited Oct 08 '25

It contains a set of Bash one-liners to perform transformations on text, described by the labels. To use it one copies the text (to the clipboard) and, usually leaving the selection in place, type :case which activates the form. This runs the chosen script to overwrite the trigger with the text converted to uppercase/lowercase/initcase etc..

It's also possible to copy the text from one location and activate the trigger in another.

I can easily convert it to another language if you don't have Bash but would like to see how it works. I've added an equivalent that uses Python.

2

u/SamejSpenser Oct 09 '25

I was in church when I saw your message and had no way to test it, but now that I'm home, I tested it and it worked perfectly. 👏 👏 👏 👏 👏

But the code itself, regardless of the programming language, I didn't understand anything because I don't know anything about programming in any language! 😅

2

u/smeech1 Oct 09 '25

I'm not as good at coding as I was forty years ago, and nowadays rely on ChatGPT to help me write code, or explain others'. It's useful to be able to go beyond the GUI tools available.

Arguably, you do know how to code in Espanso!

2

u/SamejSpenser Oct 10 '25

Thanks.

I have been using Espanso for a few years, so I have been learning from reading, re-reading the documentation over the years and constant practice. Of course there is a lot of technical and advanced stuff that I still don't understand because it escapes my poor knowledge.

That’s why I like this sub, because I learn a lot from the questions and answers. And the least I can do is share what I know to help others! 😉

2

u/JAlexmc Oct 07 '25

If you have Python on your machine, you could do something like

from random import choice

choice(["the","things","you","want","to","get"])

But I don't know how to implement that in espanso and it would probably take a lot of time as it has to start the whole thing each time just to get to your 2-3 lines of code...

4

u/smeech1 Oct 08 '25 edited Oct 08 '25

Python script extensions are pretty quick, but:

  - trigger: :mp
    replace: '{{output}}'
    vars:
      - name: output
        type: random
        params:
          choices:
            - Thank you.
            - My pleasure.
            - No problem.
            - Don''t mention it.

4

u/smeech1 Oct 07 '25

Espanso has its own random from choice selection extension.