Show HN: Espanso: detect a typed keyword and replace it while you're typing
espanso.org
espanso.org
For example I have `;out` defined to expand to the correct stdout print function depending on the programming language used in that file.
Espanso looks like it's a great way to expand the same concept to the whole system, albeit (I'm guessing) without the contextual info a text editor can provide.
That's right, out of the box espanso does not have any access to the contextual information, but with some "script gymnastics" [1] you can do plenty of interesting things :)
Definitely one of those tools that make me wonder how I got by without it
It will let you bind custom Python scripts to any mouse/keyboard sequence, including words on the fly. It can trigger word replacements just like Espanso (I use it to fill in emails, dates, addresses, timestamps et phone numbers), and of course, Python being Python, it lets you do a lot more.
The UI is probably not as good as Espanso's, and it may be harder to use (you need to script). On the other hand, it provides an API for prompting you with UI to select dates, files, input, etc., has timers and the whole Python 3 stdlib.
Some nice stuff I do with it:
- typing $email/$ phone present me with a list of email addresses/phone num (I have a lot of them) to insert one. Prevents typo. By pass web form limitations.
- $now and $date does something similar with dates (listing of various formats for the current date and a calendar). Very handy for documents and file name. Most of them don't have automated fields set up.
- $paste paste the clip board content, by passing any UI preventing me to do so, and screen/tmux limitations.
- I'm a heavy dynalist users (dynalist.io/) I love this software, but it lacks a lot of features, which are easy to add with AutoKey: just make a macro that inputs a serie of actions.
Do you plan to add scripting capabilities to Espanso or do you prefer to focus on the current use case ?
> Do you plan to add scripting capabilities to Espanso or do you prefer to focus on the current use case ?
We might add a "macro" feature to add delays and combine multiple keypresses, but I don't see espanso becoming a general "automation" tool. There are already plenty of great options for that (including AutoKey)!
It uses `rofi` and `xdotool`:
#!/bin/bash
SNIPPET_DIR="${HOME}/.config/snipex"
DMENU="rofi -dmenu -b -p Snippet:"
XSEL="/usr/bin/xsel --clipboard --input"
SNIPPET=$(ls -1 "${SNIPPET_DIR}" | ${DMENU})
FILE="${SNIPPET_DIR}/${SNIPPET}"
STRIP_NEWLINE="head -c -1"
if [ -x "${FILE}" ]; then
# snippet is executable -> run it and copy the result
${FILE} | ${STRIP_NEWLINE} | ${XSEL}
elif [ -f "${FILE}" ]; then
# copy the contents of the file
${STRIP_NEWLINE} ${FILE} | ${XSEL}
else
# clean clipboard
echo "" | ${XSEL}
fi
xdotool key --clearmodifiers "Shift+Insert"
edit: and I have an xbindkeys config to run this script when I press Meta+,[0]: https://help.gnome.org/users/zenity/stable/forms.html.en
I might switch to Espanso in the future though, given that AHK is not available on Linux.
Just tried it again. Not as slow as I remember, the syntax is also cleaner than AHK. Switching to it now :)
Feel free to ask any question, I'll be happy to answer them :)
That said, I'm currently working on another engine based on evdev that could be able to support also Wayland systems.
For the linux install see also: https://espanso.org/install/linux/
[1]: https://www.x.org/releases/X11R7.6/doc/libXtst/recordlib.htm... [2]: https://github.com/jordansissel/xdotool
I don't see myself using single program to do just expansions, but instead building my own program with Rust that has all sort of shortcuts like in AutoHotkey. I could use your expansion code as crate instead.
Started the refactor a few days ago so it's still in the early stage, but it's happening here: https://github.com/federico-terzi/espanso/tree/dev-1.x
https://crates.io/crates/enigo
And this:
https://crates.io/crates/device_query/0.2.0
respectively.
e.g. ":member(test)" => "private test;"
I’ve used aText for a long time, then semi-recently moved most things to Alfred, but I’m curious about Espanso :)
Cons: There is no GUI yet, but we are working on it
[1]: https://espanso.org/docs/forms/ [2]: https://espanso.org/docs/matches/
One more question if you're up for it: does Espanso suffer from having secure input disabled?
I frequently see this with both aText and Alfred: "Secure input is enabled (by loginwindow)" (aText) & "loginwindow seems to be preventing text expansion by locking secure entry" (Alfred)... with no indication as to how to rectify the situation.
"WARNING: An application is currently using SecureInput and might prevent espanso from working correctly."
For anyone else who ends up here with the same problem: this blog post was helpful as it suggested that locking & unlocking my system might remove the lock on secureinput created by loginwindow: https://rakhesh.com/mac/macos-find-app-using-secure-input/
Edit: Seems like it's an issue with shifted characters? When I type any trigger and erase, for example ":espanso", I expect the first character to be a colon (:) but instead I get a semi-colon (;). Weird.
backend: Clipboard
on your default.yml file and see if that helps?
backend: Clipboard works intermittently for me
I'm using the Colemak keyboard layout, and Caps Lock is mapped to Backspace.
My favorite "feature" is the fact that it works so easily cross-platform.
show_icon: false
show_notifications: false[1]: https://espanso.org/docs/forms/ [2]: https://espanso.org/docs/matches/#shell-extension
Basically, I brought some Windows keyboard shortcuts to linux. Specifically, Alt + 0,N,N,N to type accented characters. For example, è is Alt + 0,2,3,2.
Autokey was too slow, I ended up using a hacky OS keyboard shortcut + bash script approach. Ugly but it works! I should see if I can use espanso for this.
https://github.com/jeremy21212121/linux_accent_hotkeys
https://jeremypoole.ca/posts/windows_keyboard_shortcuts_on_l...
As long as the program accepts keyboard input or clipboard pasting, espanso should work correctly. There are some programs that behave a little bit differently (such as Thunderbird on Linux), that require a couple of configuration changes to work as expected (for example, slowing down the injections if the program is slow to process input).
Happy to answer any other question :)
It's 2021 and some people still don't separate UI into its own non-blocked thread.
E.g. When crunching a big dataset in QGIS (on Win10), every digit I type into "Classes" box [1] blocks everything and I have to wait.
I've just filled kate with dadjokes which isn't as sick as it sounds!
1. Espanso is cross-platform, so you create your config once and then run it on all your machines 2. Clavier comes with a GUI, but espanso does not (yet) 3. Espanso is highly flexible thanks to scripts [1] and forms [2]
1: https://espanso.org/docs/matches/#shell-extension 2: https://espanso.org/docs/forms/
I prefer this to be built in to maybe vs code, at least then I won't have to worry about accidentally capturing my passwords
TLDR: It's not a keylogger, because it doesn't log anything :)
Moreover, on macOS the detection mechanism is automatically disabled on password fields
[0]: The only real reason you wouldn't be is if you're on a non-X Linux desktop. Wayland prevents this kind of program by design.
> Have you also thought about a Wayland protocol extension?
I honestly didn't think about that! That might be an option, perhaps when espanso becomes more well-known in the community. Before that, it's unlikely that any change I suggest will make its way into the specification :)
This is meant to be a replacement to AHK (which is Windows only), not a text editor snippet expander.