Launching apps as root via dmenu

I wonder if it possible to make dmenu execute certain apps (e.g. Timeshift) as root, maybe there’s a configuration for that or some other similar way? Now I pretty much have to remember to use shortcuts (with NOPASSWD) or the terminal for such apps, which is a bit of a hassle, I’d rather prefer to use dmenu as my main app launcher. Preferably something close to vanilla i3 and (if possible) newbie friendly :slight_smile:

Don’t know about dmenu (is that a requirement?).

But you might want to start with bash aliases (don’t be afraid! It is very simple).

Simply write the aliases you want into file $HOME/.bashrc like this:

  alias update='sudo pacman -Syu'  # updates system with pacman
  alias updateall='yay -Syu'       # updates system with yay
  alias pkgcleanup='paccache -rk1' # save space and clean the package cache

and re-start a terminal. Then you’ll have commands like:

  • update
  • updateall
  • pkgcleanup

and they do exactly what you specified above. And it is very important that you know the command names and their options very well.

As you can see, the commands and their options are written there. To find out more about the commands, use the man command in terminal, e.g.:

  man pacman
  man yay

and so on.

Then, if you want a GUI for launching certain commands, you could use yad. It is quite simple to use, you’ll just write a bash script that calls yad with certain options. Here’s an example script (just modify it to your needs!):

#!/bin/bash
yad --form --title="My launcher" --width=300 \
    --field='Leafpad':fbtn 'leafpad' \
    --field='Firefox':fbtn 'firefox' \
    --field='Libreoffice':fbtn 'libreoffice --writer'

Simply write the above to a file, e.g. $HOME/bin/my-launcher. Then make it executable and put it in your PATH in order to use it later:

  chmod +x $HOME/bin/my-launcher
  export PATH=$PATH:$HOME/bin    # put this line also into $HOME/.bashrc !

Now you can start the launcher in a (new) terminal with command:

  my-launcher

Now, just click the buttons you want!

You may create a desktop icon for the launcher too. But how to do that? It is simple, so I’ll leave it to you as a further exercise. :wink:

3 Likes

In addition to the previous: making GUI programs to run as root may be really tricky and not even recommended because of security reasons.

1 Like

Thank you, @manuel , yad looks interesting I’ll read the man and try to integrate it in my workflow :slight_smile: I have been using pcmanfm as a launcher, well sort of :neutral_face: , but found myself rarely needing it.
dmenu is a dynamic menu for searching for and launching apps, which comes with i3 and that’s what I’m using the most, I’d just like it to work correctly for all apps, scripts, etc., with those requiring root access to function properly as well…

But certain apps will not function correctly (or at all) without root. If I can launch them in XFCE (for example) as root, how’s it different in this case?

X has security issues and Arch recommends not to use GUI programs as root.
Here’s much more info: https://wiki.archlinux.org/index.php/Running_GUI_applications_as_root

Terminal programs can be used with sudo/root permissions.

1 Like

you could configure sudo to not require password or even use opendoas, ayway i wouldn’t recommend to config that way,

Doesn’t timeshift come with some systemd service so you can enable and just let it run? For sure there may have some config for this on the internet.

I did that for the shortcuts (didn’t know it’s as dangerous as Arch Wiki says), but I have no idea how to make it work with dmenu…

Timeshift was just an example of a GUI app that won’t run without root access. But I’ll try to look it up, thanks

1 Like