vofdoom
Posts: 2
Joined: Wed Apr 10, 2019 7:54 pm

Run Script at Startup

Thu May 30, 2019 8:34 pm

I've seen this problem a million times and read a lot of posts about it, but it seems like everyone else is trying to do something a lot more complicated than I. All I want to do is have VLC start in full screen and load all the files in a directory into the playlist. I thought that the easiest way to do with was making a little script that ran at start up but I can't seem to get it work. When I try to simply execute the script raspbian asks me if it's and executable script and what to do with it, and I have to click "Execute" then it runs, that's about as far as I've gotten. My script is on the desktop:

Code: Select all

#!/bin/sh
# start VLC 
vlc --fullscreen "/media/pi/Room media center"
exit 0
I tried the two methods I have seen the most adding a line to both rc.local and .bashrc with the script in the home folder, neither worked. I am an absolute beginner so I know I am missing something simple. If there is an even easier way to do this, I'm all for that as well.

pcmanbob
Posts: 9298
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Run Script at Startup

Fri May 31, 2019 8:24 am

Hi.

The first thing you need to do is make your bash script executable using chmod

use of chmod is explained here https://alvinalexander.com/linux-unix/l ... irectories

Now to start your script , the use of rc.local and .bashrc is are suitable because they run scripts in the background and you want to run your script in the gui ( desktop) so you need to run the script after the gui has started.

To do that you need to add you script to the “LXDE” autostart file.

This is explained here https://www.raspberrypi-spy.co.uk/2014/ ... e-desktop/
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

ricardoaraujo00
Posts: 3
Joined: Tue Dec 10, 2019 5:47 pm

Re: Run Script at Startup

Thu Jul 02, 2020 8:59 am

You just have to edit this file
sudo nano .config/lxsession/LXDE-pi/autostart

Add this command to run a script (in this example is called shboot.sh)

@lxterminal -e /home/pi/shboot.sh

Inside that script(shboot.sh) put what you want and make it executable with "sudo chmod 755 filename"
I put those kind of scripts(shboot.sh) in my home folder..

Now it will run on LXDE desktop startup

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

Re: Run Script at Startup

Thu Jul 02, 2020 3:16 pm

ricardoaraujo00 wrote:
Thu Jul 02, 2020 8:59 am
You just have to edit this file
sudo nano .config/lxsession/LXDE-pi/autostart

Add this command to run a script (in this example is called shboot.sh)

@lxterminal -e /home/pi/shboot.sh

Inside that script(shboot.sh) put what you want and make it executable with "sudo chmod 755 filename"
I put those kind of scripts(shboot.sh) in my home folder..

Now it will run on LXDE desktop startup
By default RPi OS uses the global autostart here:

Code: Select all

/etc/xdg/lxsession/LXDE-pi/autostart 
Optionally if you prefer to create a local autostart then use this:

Code: Select all

/home/pi/.config/lxsession/LXDE-pi/autostart
I think the user will need to manually create /lxsession/LXDE-pi/ directories as they don't exist by default in the users .config directory.
If the local autostart is used then it is very important that the contents of the global autostart be copied to the local autostart.
If not done then the desktop will not start properly. Note that the global autostart is completely ignored if a local autstart exists.

For most it is much easier to use the global autostart.
Unless specified otherwise my response is based on the latest and fully updated RPiOS Buster w/ Desktop OS.

Return to “Beginners”