2

I have found many things on how to do that.

I tried with upstart, but it didn't do anything. I think I found some post that tells it doesn't come out of the box with upstart anymore. This is why this question is not a duplicate of this post.

I tried using the "Autostart" application, but whenever I add my script there, close the window and reopen it, it's gone.

I would like to execute a bash script when my user is logged in and the GUI is ready (because the script is going to open and set-up some applications). What is the best way (preferably through command line) to achieve that?

  • By "using the "Autostart" application", do you mean the interface you get via System Settings > Startup and Shutdown > Automatically started applications? That should work! Kubuntu stores the information you provide in ~/.config/autostart and ~/.config/autostart-scripts. To make sure the GUI is ready, you may need to add a sleep value at the start of your script. – DK Bose Apr 24 '18 at 15:11
  • My script is called .bash_startup and is located in my home directory. I tried adding it as a "script" in Autostart, but it kept telling me that by doing that, I would replace the script file with itself. I didn't understand why so I added it as an "Application". Now, I have a file .config/autostart/.bash_startup.desktop which has the information about my script. Still, the script doesn't seem to be loaded. – Lily Bergonzat Apr 24 '18 at 15:26
  • 1
  • If your script is small, add it to your question. 2) Have you made it executable? 3) If you're sure the script works and doesn't need a preliminary sleep, just copy the script over to ~/.config/autostart-scripts, log out and log back in. Maybe that'll work.
  • – DK Bose Apr 24 '18 at 15:34
  • 3
  • … the approach explained in muru's answer there should work fine in Kubuntu 17.10. – dessert Apr 24 '18 at 18:51
  • 1
    I suggest to wait for the main process of your desktop environment with a while loop, e.g. with while [[ ! $(pgrep plasmashell) ]]; do sleep 1; done which tests every second (at least in Kubuntu 16.04 the process is called plasmashell, adapt it if necessary). – dessert Apr 24 '18 at 19:21
  • @dessert I think it would be reasonable, and helpful, to write a specific answer here, whether or not reviewers decide to close the question... – Zanna Apr 25 '18 at 10:42