简体   繁体   中英

Automatically run graphical python script on startup in ubuntu

I have a python script that starts a fullscreen animation when run - how do i set this to start at startup in ubuntu 16.04? Other answers to the "script on startup" problem don't work - because I'm assuming they're executed before the desktop environment has a chance to start up...

I have a script called "startup.sh" that reads as:

xrandr --output HDMI-0 -s 1280x1024

source activate demo

cd ~/demo/

python run.py

Where the first line sets the correct resolution - the second line activates an anaconda environment, the third line changes directory (parts of the script need it to be in that directory, and the 4th line finally runs the script that launches a fullscreen graphic (using pygame, if it matters.)

How can i set this to auto run after unity finishes setting up? Thanks so much... any help or comments at all are really appreciated...

EDIT: it looks like someone here had a similar problem: https://www.raspberrypi.org/forums/viewtopic.php?t=128602

They wanted to start a pygame script on startup - and were able to do so after their desktop environment loaded by putting a call to their program in ~/.config/lxsession/LXDE-pi/autostart - I'm not using LXDE - i'm on unity, so is there an equivalent?

Easiest way to run things at startup is to add them to the file /etc/rc.local .

But to do this properly, you should use the update-rc.d command. You may try it like this:

update-rc.d /path_to_script/script_name.sh start 2

Or use update-rc.d /path_to_script/script_name.sh defaults to create both startup and kill scripts all at once.

For more precise actions you can visit here for details information: http://manpages.ubuntu.com/manpages/xenial/man8/update-rc.d.8.html .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM