After much trial and error where I couldn't get systemd, cron, or other methods to work, I found that at least when running the desktop, pulseaudio launches with the desktop, and must be running before my script launches. So I'm able to get my application, which requires pulseaudio, to successfully autorun on startup when Pi is set to start in desktop mode by:
- Creating a file /home/pi/.config/autostart/chatter.desktop with the following contents:
[Desktop Entry] Type=Application Name=ChatterPi Exec= /home/pi/ChatterPi/chatter.sh
- Create a /home/pi/ChatterPi/chatter.sh file with the following contents:
cd /home/pi/ChatterPi python3 main.py
and making sure the .sh file is executable by user pi.
My questions are:
- Is there a way to use systemd instead, and if so, I assume that I need to make sure that pulseaudio is already running. How do I do this?
- How can I get my code to successfully run if the Pi is set to start in command line mode, rather than desktop (need pulseaudio to be running)?
- Same question, but if Pi is running OS Lite?