[WIP] Execute custom user commands or scripts on a variety of rofi events #2053
+148
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request addresses issue #2032, making it possible to execute custom user commands or scripts on a variety of rofi events. The following events are covered for now:
Custom commands can be specified from command line as follows:
Here's an example bash script to react to "selected entry change" playing a sound:
Arguments to user commands enclosed in curly braces will be replaced with corresponding values (e.g. {entry} with currently selected or accepted entry, {error} with error text etc.). Among other things, this allows the use of a synthetic speaker (like espeak or piper) to read aloud rofi interactions. Here's an example bash script to read aloud currently selected entries using espeak:
The use of "coproc" for playing sounds with aplay is suggested, as the first example script shows, otherwise the rofi process will wait for sounds to end playback before exiting, and that can be annoying if someone concatenate multiple rofi menus (cough cough..).
Some things I don't like with current implementation:
For the callback names (on-selection-changed etc.) I tried to be descriptive enough without making them too long, but I'm certainly open to different suggestions, as well as for other rofi events worth provisioning with custom commands.
My first experiments were made using an actual C audio library integrated in rofi, but this implementation coupled with simple bash scripts does the job as well and is much more flexible.
Let me know what you think.