rofi-actions(5)

πŸ“¦
version 2.0.0 Β· 4 versions
, in alpine 3.24, ubuntu resolute, ubuntu stonking

πŸŽ€ NAME πŸŽ€

rofi-actions β€” custom commands following interaction with rofi menus πŸ’–

okay so this is the rofi-actions(5) page from the File Formats Manual, and it's literally about making rofi do cute lil extra things when you interact with it. bestie, it's giving "menu with a personality" ✨ no cap.

🌈 DESCRIPTION 🌈

rofi lets you set custom commands or scripts to run when certain actions happen in the menu β€” like when the selection changes, when you accept an entry, or when you cancel. 🫢

so like, this makes it possible to play sound effects or read aloud menu entries on selection, for example. it's that simple, fr fr. πŸ’…

πŸ’– USAGE πŸ’–

here's the list of rofi flags for specifying custom commands or scripts to execute on supported actions πŸ‘‘

  • -on-selection-changed cmd β€” command or script to run when the current selection changes. selected text is forwarded to the command replacing the pattern {entry}. πŸ¦‹
  • -on-entry-accepted cmd β€” command or script to run when a menu entry is accepted. accepted text is forwarded to the command replacing the pattern {entry}. βœ…
  • -on-mode-changed cmd β€” command or script to run when the menu mode (e.g. drun, window, ssh...) is changed. πŸ”„
  • -on-menu-canceled cmd β€” command or script to run when the menu is canceled. πŸ™ˆ
  • -on-menu-error cmd β€” 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}. πŸ’€
  • -on-screenshot-taken cmd β€” command or script to run when a screenshot of rofi is taken. screenshot path is forwarded to the command replacing the pattern {path}. πŸ“Έ

🌸 Example usage 🌸

Rofi command line: (iconic, honestly)

rofi -on-selection-changed "/path/to/select.sh {entry}" \
     -on-entry-accepted "/path/to/accept.sh {entry}" \
     -on-menu-canceled "/path/to/exit.sh" \
     -on-mode-changed "/path/to/change.sh" \
     -on-menu-error "/path/to/error.sh {error}" \
     -on-screenshot-taken "/path/to/camera.sh {path}" \
     -show drun

Rofi config file: (same vibes, but in your config)

configuration {
    on-selection-changed: "/path/to/select.sh {entry}";
    on-entry-accepted: "/path/to/accept.sh {entry}";
    on-menu-canceled: "/path/to/exit.sh";
    on-mode-changed: "/path/to/change.sh";
    on-menu-error: "/path/to/error.sh {error}";
    on-screenshot-taken: "/path/to/camera.sh {path}";
}

🎡 Play sound effects 🎡

here's an example bash script that plays a sound effect using aplay when the current selection is changed β€” it's giving "menu but make it a video game" πŸ”₯

#!/bin/bash

coproc aplay -q $HOME/Music/selecting_an_item.wav
πŸ’‘ the use of coproc for playing sounds is suggested, otherwise the rofi process will wait for sounds to end playback before exiting. so like, don't skip the coproc unless you want rofi to be dramatic and wait around. 😭

πŸ—£οΈ Read aloud πŸ—£οΈ

here's an example bash script that reads aloud currently selected entries using espeak β€” bestie, it's literally text-to-speech but make it rofi 🌸

#!/bin/bash

killall espeak
echo "selected: $@" | espeak

and that's the whole page, periodt. πŸ’… this was rofi-actions(5), from the File Formats Manual, brought to you by rofi β€” catch you in the next manpage, bestie πŸ«Άβœ¨πŸŽ€

πŸ“¦ where this page comes from