Automatically run graphical python script on startup












1















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?










share|improve this question























  • "Other answers to the "script on startup" problem don't work...". What don't work? What have you tried specifically?

    – j-money
    Feb 1 at 8:38











  • Have you tried adding it to "startup applications" (accessible from the dash)?

    – danzel
    Feb 1 at 8:42











  • @j-money I have tried adding it to "startup applications" and setting a cron job

    – Robbie Barrat
    Feb 1 at 8:50











  • @danzel yes - see above

    – Robbie Barrat
    Feb 1 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 at 8:53
















1















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?










share|improve this question























  • "Other answers to the "script on startup" problem don't work...". What don't work? What have you tried specifically?

    – j-money
    Feb 1 at 8:38











  • Have you tried adding it to "startup applications" (accessible from the dash)?

    – danzel
    Feb 1 at 8:42











  • @j-money I have tried adding it to "startup applications" and setting a cron job

    – Robbie Barrat
    Feb 1 at 8:50











  • @danzel yes - see above

    – Robbie Barrat
    Feb 1 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 at 8:53














1












1








1








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?










share|improve this question














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?







unity python cron startup autostart






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Feb 1 at 8:28









Robbie BarratRobbie Barrat

112




112













  • "Other answers to the "script on startup" problem don't work...". What don't work? What have you tried specifically?

    – j-money
    Feb 1 at 8:38











  • Have you tried adding it to "startup applications" (accessible from the dash)?

    – danzel
    Feb 1 at 8:42











  • @j-money I have tried adding it to "startup applications" and setting a cron job

    – Robbie Barrat
    Feb 1 at 8:50











  • @danzel yes - see above

    – Robbie Barrat
    Feb 1 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 at 8:53



















  • "Other answers to the "script on startup" problem don't work...". What don't work? What have you tried specifically?

    – j-money
    Feb 1 at 8:38











  • Have you tried adding it to "startup applications" (accessible from the dash)?

    – danzel
    Feb 1 at 8:42











  • @j-money I have tried adding it to "startup applications" and setting a cron job

    – Robbie Barrat
    Feb 1 at 8:50











  • @danzel yes - see above

    – Robbie Barrat
    Feb 1 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 at 8:53

















"Other answers to the "script on startup" problem don't work...". What don't work? What have you tried specifically?

– j-money
Feb 1 at 8:38





"Other answers to the "script on startup" problem don't work...". What don't work? What have you tried specifically?

– j-money
Feb 1 at 8:38













Have you tried adding it to "startup applications" (accessible from the dash)?

– danzel
Feb 1 at 8:42





Have you tried adding it to "startup applications" (accessible from the dash)?

– danzel
Feb 1 at 8:42













@j-money I have tried adding it to "startup applications" and setting a cron job

– Robbie Barrat
Feb 1 at 8:50





@j-money I have tried adding it to "startup applications" and setting a cron job

– Robbie Barrat
Feb 1 at 8:50













@danzel yes - see above

– Robbie Barrat
Feb 1 at 8:50





@danzel yes - see above

– Robbie Barrat
Feb 1 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 at 8:53





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 at 8:53










1 Answer
1






active

oldest

votes


















1














You might try something like this?



[Unit]
Description=Start some anaconda service (?)
Requires=graphical.target

[Service]
ExecStart=path/to/your/script


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!






share|improve this answer
























  • IIRC, graphical.target is reached before the display manager starts.

    – danzel
    Feb 1 at 9:43











  • thank you for the hint - i'm trying this currently...

    – Robbie Barrat
    Feb 1 at 9:55











  • @danzel I honestly don't remember :/ what would you recommend so I can improve the answer?

    – j-money
    Feb 1 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 at 10:07











  • See danzel's comment

    – j-money
    Feb 1 at 10:11











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1114656%2fautomatically-run-graphical-python-script-on-startup%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














You might try something like this?



[Unit]
Description=Start some anaconda service (?)
Requires=graphical.target

[Service]
ExecStart=path/to/your/script


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!






share|improve this answer
























  • IIRC, graphical.target is reached before the display manager starts.

    – danzel
    Feb 1 at 9:43











  • thank you for the hint - i'm trying this currently...

    – Robbie Barrat
    Feb 1 at 9:55











  • @danzel I honestly don't remember :/ what would you recommend so I can improve the answer?

    – j-money
    Feb 1 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 at 10:07











  • See danzel's comment

    – j-money
    Feb 1 at 10:11
















1














You might try something like this?



[Unit]
Description=Start some anaconda service (?)
Requires=graphical.target

[Service]
ExecStart=path/to/your/script


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!






share|improve this answer
























  • IIRC, graphical.target is reached before the display manager starts.

    – danzel
    Feb 1 at 9:43











  • thank you for the hint - i'm trying this currently...

    – Robbie Barrat
    Feb 1 at 9:55











  • @danzel I honestly don't remember :/ what would you recommend so I can improve the answer?

    – j-money
    Feb 1 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 at 10:07











  • See danzel's comment

    – j-money
    Feb 1 at 10:11














1












1








1







You might try something like this?



[Unit]
Description=Start some anaconda service (?)
Requires=graphical.target

[Service]
ExecStart=path/to/your/script


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!






share|improve this answer













You might try something like this?



[Unit]
Description=Start some anaconda service (?)
Requires=graphical.target

[Service]
ExecStart=path/to/your/script


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!







share|improve this answer












share|improve this answer



share|improve this answer










answered Feb 1 at 9:35









j-moneyj-money

1,093416




1,093416













  • IIRC, graphical.target is reached before the display manager starts.

    – danzel
    Feb 1 at 9:43











  • thank you for the hint - i'm trying this currently...

    – Robbie Barrat
    Feb 1 at 9:55











  • @danzel I honestly don't remember :/ what would you recommend so I can improve the answer?

    – j-money
    Feb 1 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 at 10:07











  • See danzel's comment

    – j-money
    Feb 1 at 10:11



















  • IIRC, graphical.target is reached before the display manager starts.

    – danzel
    Feb 1 at 9:43











  • thank you for the hint - i'm trying this currently...

    – Robbie Barrat
    Feb 1 at 9:55











  • @danzel I honestly don't remember :/ what would you recommend so I can improve the answer?

    – j-money
    Feb 1 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 at 10:07











  • See danzel's comment

    – j-money
    Feb 1 at 10:11

















IIRC, graphical.target is reached before the display manager starts.

– danzel
Feb 1 at 9:43





IIRC, graphical.target is reached before the display manager starts.

– danzel
Feb 1 at 9:43













thank you for the hint - i'm trying this currently...

– Robbie Barrat
Feb 1 at 9:55





thank you for the hint - i'm trying this currently...

– Robbie Barrat
Feb 1 at 9:55













@danzel I honestly don't remember :/ what would you recommend so I can improve the answer?

– j-money
Feb 1 at 10:02





@danzel I honestly don't remember :/ what would you recommend so I can improve the answer?

– j-money
Feb 1 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 at 10:07





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 at 10:07













See danzel's comment

– j-money
Feb 1 at 10:11





See danzel's comment

– j-money
Feb 1 at 10:11


















draft saved

draft discarded




















































Thanks for contributing an answer to Ask Ubuntu!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1114656%2fautomatically-run-graphical-python-script-on-startup%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

Mangá

 ⁒  ․,‪⁊‑⁙ ⁖, ⁇‒※‌, †,⁖‗‌⁝    ‾‸⁘,‖⁔⁣,⁂‾
”‑,‥–,‬ ,⁀‹⁋‴⁑ ‒ ,‴⁋”‼ ⁨,‷⁔„ ‰′,‐‚ ‥‡‎“‷⁃⁨⁅⁣,⁔
⁇‘⁔⁡⁏⁌⁡‿‶‏⁨ ⁣⁕⁖⁨⁩⁥‽⁀  ‴‬⁜‟ ⁃‣‧⁕‮ …‍⁨‴ ⁩,⁚⁖‫ ,‵ ⁀,‮⁝‣‣ ⁑  ⁂– ․, ‾‽ ‏⁁“⁗‸ ‾… ‹‡⁌⁎‸‘ ‡⁏⁌‪ ‵⁛ ‎⁨ ―⁦⁤⁄⁕