Better Control for Startup Applications

The Startup Applications function can be a challenge. The environment doesn't allow simple multiple commands like a delay and there's no way to order things if need be. The same exact commands that run fine in a terminal may fail to run in Startup Applications for many reasons.

My solution is simple. Make a customized bash script and add it to Startup Applications then simply edit that bash script as needed. Here's how...

Create ~/bin/startup.sh, make it executable and open it for editing
I'll do the terminal version then use pluma but you can always do this your way.

In a terminal:

mkdir ~/bin
touch ~/bin/startup.sh
chmod +x ~/bin/startup.sh
pluma ~/bin/startup.sh

Add your commands.
Here's an example file with "#" comments.

#!/bin/bash

# Delay 1 second
sleep 1

# Play the Ubuntu login sound
/usr/bin/paplay --volume=50000 /usr/share/sounds/ubuntu/stereo/desktop-login.ogg &

# Delay 2 seconds
sleep 2

# Start Conky using my custom config file
/usr/bin/conky -c /home/bill/.conky/conkymain &
  1. Be sure and include the #!/bin/bash on the first line so it runs in a bash shell to help ensure it works same as a terminal.

  2. Notice how the commands end with a "&". If not included, the script will run the command then wait for it to exit. This isn't good for many things and will effectively hold this script hostage for the entire session. Adding the "&" runs the command in the background then goes on - exactly what you usually want.

  3. The sleep commands do NOT get the "&" which is important if you want the delay to actually work.

  4. I'm an old purist so I do all paths explicitly. It probably isn't needed but I like it that way.

Save when you're done.

Test it out.
Did you wonder why I put this file in ~/bin? It turns out this old convention for user programs remains alive and well in Mate. When you login, this directory (if it exists) is added to $PATH so you can just type the command name.

If ~/bin is new you may have to logout/login for it to be added to $PATH.

In a terminal, simply enter startup.sh and the file will run. Results vary with what gets started by the script.

Do all the delays seem appropriate?

Did it return as expected to the terminal prompt when it completed? This is a good check you have all the "&" properly in place.

Add the script to Startup Applications.
Pretty straight forward. I title mine AAA-Startup so it's alphabetically on top.

System -> Preferences -> Personal -> Startup Applications
Click Add.

From now on, tweak your ~/bin/startup.sh file as you like, and with better control of things.

10 Likes

Straight-forward and to the point. Though, you can add sleep commands, just, everything you want to run needs to be inline shell commands.

This does, however open the door for discussion about improving MATE’s startup stuff…

1 Like

Hi @tiox, I started doing this due to a nasty startup file naming bug: https://github.com/mate-desktop/mate-control-center/issues/105

There’s been a little discussion, mostly about adding delays. I never worried about this…

command1 &
command2 &
command3 &

Sure they’re inline but separated by what, 100msec? :slight_smile:

@Bill_MI
Thanks for your post. I do something similar with shell scripts in Ubuntu MATE in order to control the order of application startup. I really like the way that Linux Mint has implemented delays in their the startup app. Completely eliminates the need for custom startup scripts for me. Each app in the startup app has its own delay setting available.

Scripts are not really difficult or a problem for me, but I think if Ubuntu MATE could implement something like what Mint has done would make this a much easier and more discoverable way of managing order of application startup.

Hi @goinglinux, And a big shout out to you, Larry, for all you’ve done for helping new users for many years.

It’s been awhile since I saw Mint but that sounds like a good idea and it’s been suggested a lot. And the pressure surely gets a boost if Mint’s doing it. :relaxed:

@marfig posted a feature request for this back in September:

Feel free to back the issue on bountysource. :]

And all it’ll do most likely is add sleep n to the file, where users can, if they wanted to, make it use sh instead as follows;
sh -c "sleep 5 && foo --arg 'baz'"

1 Like

i just tried this and i still cant get it to work. i followed all your steps.
my startup.sh has:
#!/bin/bash sleep 2 xset s off & xset -dpms & xset s noblank & feh --quiet --fullscreen --borderless --hide-pointer --randomize --slideshow-delay 30 /media/usb/* &

i open terminal and typed in: startup.sh
and it works fine. BUT when i follow your instruction to add to Startup Applications, it refuses to load FEH and play photos from my usb drive.
pls help

This could be implemented using cron. Something like

@reboot /bin/sleep 1; script.sh

don’t know if that’s the smartest way though

Does X-GNOME-Autostart-Delay=1 in the .desktop file work in MATE?

EDIT:
I saw some X-MATE-Autostart-Delay in the MATE code. Is that the correct way to get delay?

Hi @Philly_Hot, Not sure. Here’s some possibilities…

Is 2 second delay too short? Try ridiculously high like 30 seconds to prove it’s not that.

For the startup “Command” field try explicit path if you haven’t. Use your real home directory name, of course. The app can also browse for the startup.sh file and automatically makes it explicit.

/home/philly_hot/bin/startup.sh

I use the whole path for everything. Even the xset and feh commands. For example, find where xset is:

which xset
/usr/bin/xset

Replace the feh with galculator (Calculator) or something else you choose just to prove the script does run. Either the script doesn’t run or feh fails and it would be nice to know which it is

Since it works in the terminal everything else I can think of cannot be the problem.

i spent 12 hours trying all 5 methods found here: https://www.dexterindustries.com/howto/run-a-program-on-your-raspberry-pi-at-startup/

then luckily i found your post. first i tried sleep=2 and that didnt work. for the next 3 hours, i tried everything else again. finally i went back to your method and try sleep=15.
that works! so total of about 15hours trying to get a script to auto launch after desktop gui comes up.
thanks again.

One of the problems is those startup programs are NOT started after the desktop is fully up but get executed in the middle of a lot of desktop things initializing. It simply isn’t ready. And if this is a Raspberry Pi that explains why it took 15 seconds to be ready. Glad it’s working!