1

I have a console application, which I run as root from the shell. But now, I need to create a shortcut on the Desktop, where I click on it, and it should appear the shell (in root) and the application running. How can I do this?

I've seen this.

Where I've done the following:

sudo apt install gnome-panel

sudo apt install gksu

gnome-desktop-item-edit ~/Desktop/ --create-new

Where I've set up the shortcut. But if I run the application, nothing works and I do not see the shell.

I'm using Ubuntu 16.04.

waas1919
  • 125

1 Answers1

1

So inside your .desktop entry you need to put the following on the exec line:

Exec=gnome-terminal.real -- YOUR_COMMAND and on the Terminal line Terminal=true

The -- in the Exec line means that the command after it will be executed in the new terminal.

So for example if you want to start a python application as root when you click on the desktop icon your .desktop file should look something like this:

[Desktop Entry]
Version=1.0
Type=Application
Name=The app name
Icon=/absolute/path/to/an/icon.png
Exec=gnome-terminal.real -- sudo python /absolute/path/to/your/script.py
Comment=Some longer description of what your program does.
Categories=Utility;
Terminal=true

So when a user clicks on your desktop icon they will see a terminal window that displays a password prompt like this:

Password prompt after clicking on desktop icon

And after the prompt your program is run.

Daniel W.
  • 3,436
  • If you want to be able to run it without being prompted for the sudo password you can run sudo visudo and a a line like <USERNAME> <HOSTNAME> = (root) NOPASSWD: <PATH/TO/COMMAND> as in this answer – derHugo Nov 09 '17 at 17:36