Executing a script after the user has logged in, on Raspberry Pi
Solution 1
Add the script to the /etc/rc.local
file.
On the Raspberry Pi, open /etc/rc.local
with a text editor. I use Vim, with the sudo
command.
Once you open you the file, you will see something like this:
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
fi
# Add your script here
/home/pi/somescript.sh
exit 0
Once you've added the path to your script the file will be executed at reboot. If you want to run at login do the same thing, but edit your .bashrc
file instead.
Solution 2
Assuming the desktop is LXDE, LXSession can be used to automatically start application on login. To configure this: Menu -> Preferences -> Default applications for LXSession
Click on "Autostart" * Disable autostarted applications? = No
In the box next to "+Add" enter the name of the application and then press "+Add", it will appear under "Manual autostarted applications.
Logout and log back in again, the application should start.
user2632811
Updated on June 05, 2022Comments
-
user2632811 almost 2 years
I have developed an application for the user to see certain times on screen. I am using the pygames library and the GUI is full screen after the user runs the .py file.
I want a solution so that the user does not need to run the file, but rather the file gets executed by itself after the log in is complete.