2

Simply put, how can I do this, providing a graphical prompt?

I tried creating a separate bash script that when opened, ran the Python script with super-user permissions - I used gksu -u root '<script>'.

Unfortunately, it didn't work... :(

Any ideas?

TellMeWhy
  • 17,964
  • 41
  • 100
  • 142

2 Answers2

3

The appropriate way to start any process or application via GUI is using a .desktop file. You can also use it to run scripts with sudo privileges. In its simplest form that would be:

[Desktop Entry]
Name=Some Name
Exec=gksu python3 /path/to/script 
Type=Application

If the script is executable, you could simply use:

Exec=gksu /path/to/script 

In the Exec= -line

important notes

  • You need to make the .desktop file executable to make it work on double- click.
  • You can "dress up" the .desktop file with more options, such as an icon etc., as shown here.

Alternatively

More complicated and kind of a detour, but it should be mentioned nevertheless:
You could set nautilus to run (executable) scripts on double- click, as described here.

Then (doing it "your way"), a separate bash script:

#!/bin/bash
gksu python3 /path/to/script

made executable, would also run the python script, similarly to the .desktop file.

Jacob Vlijm
  • 85,475
1

Sorry not enough rep to commet. Did your try giving the file the correct permissions. Try giving rwx to everyone to see if that works, you can change it to your desired setting later.

sudo chmod 777 'script.py'.

Try this to fix the path problem

gksudo ./script