|
| 1 | +# rofi-actions(5) |
| 2 | + |
| 3 | +## NAME |
| 4 | + |
| 5 | +**rofi-actions** - Custom commands following interaction with rofi menus |
| 6 | + |
| 7 | +## DESCRIPTION |
| 8 | + |
| 9 | +**rofi** allows to set custom commands or scripts to be executed when some actions are performed in the menu, such as changing selection, accepting an entry or canceling. |
| 10 | + |
| 11 | +This makes it possible for example to play sound effects or read aloud menu entries on selection. |
| 12 | + |
| 13 | +## USAGE |
| 14 | + |
| 15 | +Following is the list of rofi flags for specifying custom commands or scripts to execute on supported actions: |
| 16 | + |
| 17 | +`-on-selection-changed` *cmd* |
| 18 | + |
| 19 | +Command or script to run when the current selection changes. Selected text is forwarded to the command replacing the pattern *{entry}*. |
| 20 | + |
| 21 | +`-on-entry-accepted` *cmd* |
| 22 | + |
| 23 | +Command or script to run when a menu entry is accepted. Accepted text is forwarded to the command replacing the pattern *{entry}*. |
| 24 | + |
| 25 | +`-on-mode-changed` *cmd* |
| 26 | + |
| 27 | +Command or script to run when the menu mode (e.g. drun,window,ssh...) is changed. |
| 28 | + |
| 29 | +`-on-menu-canceled` *cmd* |
| 30 | + |
| 31 | +Command or script to run when the menu is canceled. |
| 32 | + |
| 33 | +`-on-menu-error` *cmd* |
| 34 | + |
| 35 | +Command or script to run when an error menu is shown (e.g. `rofi -e "error message"`). Error text is forwarded to the command replacing the pattern *{error}*. |
| 36 | + |
| 37 | +`-on-screenshot-taken` *cmd* |
| 38 | + |
| 39 | +Command or script to run when a screenshot of rofi is taken. Screenshot path is forwarded to the command replacing the pattern *{path}*. |
| 40 | + |
| 41 | +### Example usage |
| 42 | + |
| 43 | +Rofi command line: |
| 44 | + |
| 45 | +```bash |
| 46 | +rofi -on-selection-changed "/path/to/select.sh {entry}" \ |
| 47 | + -on-entry-accepted "/path/to/accept.sh {entry}" \ |
| 48 | + -on-menu-canceled "/path/to/exit.sh" \ |
| 49 | + -on-mode-changed "/path/to/change.sh" \ |
| 50 | + -on-menu-error "/path/to/error.sh {error}" \ |
| 51 | + -on-screenshot-taken "/path/to/camera.sh {path}" \ |
| 52 | + -show drun |
| 53 | +``` |
| 54 | + |
| 55 | +Rofi config file: |
| 56 | + |
| 57 | +```css |
| 58 | +configuration { |
| 59 | + on-selection-changed: "/path/to/select.sh {entry}"; |
| 60 | + on-entry-accepted: "/path/to/accept.sh {entry}"; |
| 61 | + on-menu-canceled: "/path/to/exit.sh"; |
| 62 | + on-mode-changed: "/path/to/change.sh"; |
| 63 | + on-menu-error: "/path/to/error.sh {error}"; |
| 64 | + on-screenshot-taken: "/path/to/camera.sh {path}"; |
| 65 | +} |
| 66 | +``` |
| 67 | + |
| 68 | +### Play sound effects |
| 69 | + |
| 70 | +Here's an example bash script that plays a sound effect using `aplay` when the current selection is changed: |
| 71 | + |
| 72 | +```bash |
| 73 | +#!/bin/bash |
| 74 | + |
| 75 | +coproc aplay -q $HOME/Music/selecting_an_item.wav |
| 76 | +``` |
| 77 | + |
| 78 | +The use of `coproc` for playing sounds is suggested, otherwise the rofi process will wait for sounds to end playback before exiting. |
| 79 | + |
| 80 | +### Read aloud |
| 81 | + |
| 82 | +Here's an example bash script that reads aloud currently selected entries using `espeak`: |
| 83 | + |
| 84 | +```bash |
| 85 | +#!/bin/bash |
| 86 | + |
| 87 | +killall espeak |
| 88 | +echo "selected: $@" | espeak |
| 89 | +``` |
0 commit comments