If you’re running Raspian on a Raspberry Pi 4 and want to execute commands after the GUI has loaded, here’s how.
First, we’re going to open the
# Note: Do NOT run in sudo mode. You will edit the wrong file! nano ~/.config/lxsession/LXDE-pi/autostart
And we’re going to add the following:
@lxpanel --profile LXDE-pi @pacmanfm --desktop --profile LXDE-pi # Run a sample bash script @sh /home/pi/your/script.sh # Or a sample python script @python /home/pi/python_script.py
X to write changes to disk,
Y to confirm, and
Enter to save the file.
That’s it! Go ahead and run
sudo reboot to test it out!
I use this strategy to run a python server and React-powered UI for a digital photo frame.
Note: Make sure that you’ve run
sudo raspi-config and set
Boot Options to
Desktop Autologin for best results.