eobard
Posts: 4
Joined: Sat Aug 22, 2015 4:47 pm

".desktop" file and SUDO python help

Sun Aug 23, 2015 2:24 am

So I got the bump of help I needed for fixing my python code to automate my lights here viewtopic.php?f=32&t=118783&p=806280. My next two stumbling blocks are in making a single, clickable icon so that any device tied into my network can control the lights over VNC. I've proven it works by typing the commands in a terminal on my desktop, netbook and phone but I want it to be just "click 'n go". So I made a ".desktop" file that wouldn't work. It kept giving me an error that it was invalid. I figured it was because I was using it to launch a shell script so I changed the Exec to the actual python in /usr/bin and now the error message is gone but I'm getting no results. Here's where I was:

Code: Select all

[Desktop Entry]
Type=Application
Name=Light
Exec=//home/pi/Desktop/L1.sh
Icon=/home/pi/Downloads/lightbulb.ico
Terminal=false
Which gave me the error "Invalid desktop entry"
I narrowed it down to the Exec line so I changed it to run python's IDE and it would launch the IDE

Code: Select all

[Desktop Entry]
Type=Application
Name=Light
Exec=/usr/bin/idle-python3.2
Icon=/home/pi/Downloads/lightbulb.ico
Terminal=false
but I don't want to launch the IDE, I just want to quietly run the code. So I changed it to the following:

Code: Select all

[Desktop Entry]
Type=Application
Name=Light
Exec=/usr/bin/python3.2 /home/pi/l1a.py
Icon=/home/pi/Downloads/lightbulb.ico
Terminal=false
thinking/hoping it would run python and pass "l1a.py" as a variable to python to have it execute that program. But when I click on the icon nothing happens. I think I know why but I'm not 100% sure. I think it's because I'm trying to run a program that needs sudo permission and I'm not giving it any way of informing me that this is what's tripping me up. If I'm wrong about this or have a syntax error by all means let me know. But assuming I'm right I'm on to part two: running the file as root. I've edited my sudoers permission file as follows to give python permission to run without needing password:

Code: Select all

pi ALL = NOPASSWD: /usr/bin/python3.2
but it still doesn't work. I think I've solved the first half of my issues, but not sure what to do about this second part. Anyone got any ideas?

JimmyN
Posts: 1109
Joined: Wed Mar 18, 2015 7:05 pm
Location: Virginia, USA

Re: ".desktop" file and SUDO python help

Sun Aug 23, 2015 11:23 am

Try

Code: Select all

Exec=sudo /usr/bin/python3 /home/pi/l1a.py

eobard
Posts: 4
Joined: Sat Aug 22, 2015 4:47 pm

Re: ".desktop" file and SUDO python help

Sun Aug 23, 2015 1:29 pm

Perfect! You people are 2 for 2 and in very rapid time!

Thanks.

Return to “Python”