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?

  • "Other answers to the "script on startup" problem don't work...". What don't work? What have you tried specifically? – j-money Feb 1 '19 at 8:38
  • Have you tried adding it to "startup applications" (accessible from the dash)? – danzel Feb 1 '19 at 8:42
  • @j-money I have tried adding it to "startup applications" and setting a cron job – Robbie Barrat Feb 1 '19 at 8:50
  • @danzel yes - see above – Robbie Barrat Feb 1 '19 at 8:50
  • you might try writing a unit file for systemd and enabling it, and in your script a hacky way might be to just tell it to sleep N to wait for the X environment. Or if I remember correctly unit files have a flag that tell them to wait for certain events? – j-money Feb 1 '19 at 8:53

You might try something like this?

Description=Start some anaconda service (?)    


I personally haven't tested it, so you'll have to let me know if it works. For better reference here is the unit file page!

Also, make sure you enable the file when your done!

| improve this answer | |
  • IIRC, graphical.target is reached before the display manager starts. – danzel Feb 1 '19 at 9:43
  • thank you for the hint - i'm trying this currently... – Robbie Barrat Feb 1 '19 at 9:55
  • @danzel I honestly don't remember :/ what would you recommend so I can improve the answer? – j-money Feb 1 '19 at 10:02
  • unfortunately still not working - im guessing that it is executing before unity starts up, because the monitors aren't switched by the xrandr command (when i run the command after unity starts up it switches off one monitor and on another) – Robbie Barrat Feb 1 '19 at 10:07
  • See danzel's comment – j-money Feb 1 '19 at 10:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.