Phedg1
Posts: 5
Joined: Mon Jun 24, 2019 6:48 am

Need help getting a python script that starts a gui process to autostart

Tue Mar 17, 2020 3:50 pm

Hi,
I don't know if this belongs in the Beginners, Troubleshooting or Advanced Users subforum. When my raspberry pi boots I would like it to look for all the video files in a particular directory then launch VLC with those videos playing as a playlist, on a loop. I wrote a python script that does this, with VLC being launched at the end using subprocess.Popen(). The final step was to get this to autostart when the pi boots. I tried editing /etc/rc.local, adding the command "/usr/bin/python" "/home/pi/Documents/Autoplay VLC.py" but nothing seemed to happen. After some Googling I tried editing /home/pi/.config/lxsession/LXDE-pi/autostart and added sleep 5 @"/usr/bin/python" "/home/pi/Documents/Autoplay VLC.py" so that it was only run once the GUI had been initialized. Still no dice. I tried making it run through the lxterminal @lxterminal -e "/usr/bin/python" "/home/pi/Documents/Autoplay VLC.py" but I'm left with a blank terminal on boot. I tried running the same command in a normal terminal and it ran fine. I tried adding sudo at the start and it didn't run. I don't know for sure, but I am image that commands in the autostart file are run as root. More Googling and I have found that no GUI applications can be run as root.

How can I get my script to autorun as the local user, so it actually opens the VLC window?
I've been pulling my hair out for a number of hours and this is as far as I have gotten.

klricks
Posts: 7154
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: Need help getting a python script that starts a gui process to autostart

Tue Mar 17, 2020 3:59 pm

Remove the "" from lxterminal command:

Code: Select all

@lxterminal -e /usr/bin/python /home/pi/Documents/Autoplay VLC.py
Unless specified otherwise my response is based on the latest and fully updated RPiOS Buster w/ Desktop OS.

Phedg1
Posts: 5
Joined: Mon Jun 24, 2019 6:48 am

Re: Need help getting a python script that starts a gui process to autostart

Tue Mar 17, 2020 4:04 pm

klricks wrote:
Tue Mar 17, 2020 3:59 pm
Remove the "" from lxterminal command:

Code: Select all

@lxterminal -e /usr/bin/python /home/pi/Documents/Autoplay VLC.py
That did not appear to do anything. No terminal window is brought up, the script did not appear to open vlc. (I thought because there's a space between Autoplay and VLC that it needed quotes, I started to put them everywhere out of paranoia)

DirkS
Posts: 10363
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Need help getting a python script that starts a gui process to autostart

Tue Mar 17, 2020 4:15 pm

Because there's a space in the path/filename you will need quotes around the full path to the script.
I would actually remove the space or replace it with an underscore.

klricks
Posts: 7154
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: Need help getting a python script that starts a gui process to autostart

Tue Mar 17, 2020 4:17 pm

Phedg1 wrote:
Tue Mar 17, 2020 4:04 pm
klricks wrote:
Tue Mar 17, 2020 3:59 pm
Remove the "" from lxterminal command:

Code: Select all

@lxterminal -e /usr/bin/python /home/pi/Documents/Autoplay VLC.py
That did not appear to do anything. No terminal window is brought up, the script did not appear to open vlc. (I thought because there's a space between Autoplay and VLC that it needed quotes, I started to put them everywhere out of paranoia)
Since " are not allowed you cannot have any filenames with spaces.
Unless specified otherwise my response is based on the latest and fully updated RPiOS Buster w/ Desktop OS.

Phedg1
Posts: 5
Joined: Mon Jun 24, 2019 6:48 am

Re: Need help getting a python script that starts a gui process to autostart

Tue Mar 17, 2020 4:29 pm

That was it. Remove the "" from the whole line and remove any spaces. You guys are life savers. Thank you.

Return to “Advanced users”