If you need to run commands as root regularly with Rofi, you may find this useful.

So let’s say you want to run usb-creator-gtk to create a bootable USB stick. You have write access to the USB stick’s block device but it’s not enough: you need to become root.

You can of course open a terminal and run sudo usb-creator-gtk. But it’s kind of tedious if you need to do that more than once.

If you want to permanently run that command as root, do this:

  • sudo visudo to edit the /etc/sudoers file.
  • Add the line yourusername ALL = NOPASSWD: /usr/bin/usb-creator-gtk
  • Confirm that you can now run the command as root without being asked your password: sudo usb-creator-gtk should pop the USB Creator window rightaway.
  • Create a desktop entry in your home directory that will override the system-wide one: cp /usr/share/applications/usb-creator-gtk.desktop ~/.local/share/applications/

That way, when Rofi looks for available applications in drun mode, it will find your local usb-creator-gtk.desktop file before the system-wide file of the same name and will use the local one and ignore the system-wide one.

If you’d like Rofi to list both, rename the one in your local directory to a different name from the system-wide one.

  • Edit ~/.local/share/applications/usb-creator-gtk.desktop:
    • Modify Exec=usb-creator-gtk to Exec=sudo usb-creator-gtk.
    • Modify Name=Startup Disk Creator to Name=Startup Disk Creator (sudo), so you know Rofi picks your local desktop file over the system-wide one, or you can tell the sudo version apart from the normal version if you want to keep both listed.

And that’s it!

Start Rofi, type “startup” and the autocompletion should list “Startup Disk Creator (sudo)” - and of course, selecting it should pop the window rightaway.