Linux Mint (Nemo) - Add "run as root" in start context menu 
Sunday, 6 October 2019, 13:18 - Informatica, Linux
Today we'll see how to add a custom menu entry to the context menu of the applications listed in the "start menu" in Linux Mint. Mint uses Nemo as file manager, and the start menu is implemented by an applet written in javascript. In this article we will add a custom entry to run any application as root. By clicking the entry the applet will call a custom reusable script placed under a directory of our choice.
To add a custom entry to the context menu we have to edit the menu applet. Follow these steps:
1) go to "/usr/share/cinnamon/applets/menu@cinnamon.org".
2) edit the file named "applet.js";
3) scroll down to the ApplicationContextMenuItem class definition;
4) find the "activate" method and add the following case to the switch code block:
            case "run_as_root":
Util.spawnCommandLine("gnome-terminal -- /usr/local/sbin/runasroot " + this._appButton.app.get_app_info().get_filename());
break;

5) scroll down to the GenericApplicationButton class definition;
6) find the "populateMenu" method and add the following lines before the method close:
        menuItem = new ApplicationContextMenuItem(this, "Run as root", "run_as_root", "locked");
menu.addMenuItem(menuItem);


feel free to edit the second parameter to match your language. The last parameter is thi icon name, unfotunately I had no luck to show a custom icon yet.
7) save the file;
8) go to "/usr/local/sbin/" and create a file named "runasroot" with the following content:
#!/bin/bash

name=$(grep Name= $1|awk -F '=' '{print $2}')
pgm=$(grep Exec= $1|awk -F ' |=' '{print $2}')

echo "Running $name as root..."
sudo -b $pgm > /dev/null 2>&1

exit 0

9) set the file permission to 755;
10) right click the task bar, choose "problem resolution" -> "Restart Cinnamon".

Now you can see the new context menu entry:


If you tap the entry, a terminal window will ask you for your password and starts the application:


The app is started as root:


That's all!

Commenti

Aggiungi commento
Commento non disponibile per questa notizia.