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,484
  • 1
    creating a .desktop file with the command gksu python3 /path/to/script should work. Must be a dupe of something. – Jacob Vlijm Nov 03 '15 at 15:54
  • @JacobVlijm I've looked a LOT and can't find anything. Why a .desktop file? – TellMeWhy Nov 03 '15 at 16:00
  • 1
    A .desktop file is the appropriate GUI way to start any process or application via GUI, similar to: http://askubuntu.com/questions/626434/launching-a-sh-file-from-a-launcher/626513#626513. Alternatively, you can set nautilus to run executable scripts on double- click, but I'd prefer the general way. – Jacob Vlijm Nov 03 '15 at 16:02
  • @JacobVlijm thanx, could you post an answer so I can give you credit? – TellMeWhy Nov 03 '15 at 16:09

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
  • 83,767
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