Note: this wiki is no longer maintained. If you have any questions related to this wiki, please post them on the CrunchBang forums.

Translations of this page?:

DESKTOP Autostart applications when openbox starts

What is this autostart.sh (or just 'autostart' in Statler 10) and how can I edit it?

autostart.sh is a script that openbox executes each time it opens. Here you can put your commands to autostart applications or execute scripts you like to run when you start the computer.

You can edit your autostart.sh directly from /home/user/.config/openbox/autostart.sh, or through the root-menu in preferences>openbox>edit autostart.sh.

Note: remember that this file is called simply “autostart” (and not “autostart.sh”) in #! 10 (Statler) and 11 (Waldorf).

Basic syntax

The syntax of autostart.sh is actually just a list of commands from the terminal that executes at the same time.

# application_description
application_command &

the first line is a comment; it actually does nothing, and is frankly quite useless for the computer, it ignores all text after a '#' but it can prove to be useful for you. If the application has a name that does not explain what it is, or you've added settings to it. You might want to write something here to remember what the command actually does. Otherwise you will have an autostart file that you do not understand.

The second line is what is actually executed, in the previous example we execute 'application_command' without options or anything else, plain and simple and it executes when the script is run.

The '&' at the end of the command indicates that it should be run in the background, what this does is allow Openbox to move on to the next command. If we just called 'application_command' (without the &) Openbox wouldn't move on to anything else until application-command had finished, which might be never.

But what if the program is not executed?

Then you've typed the wrong command. Try typing the command in the terminal (without the '&' suffix), it should work exactly the same way in the terminal as in the autostart file.

(The only possible catch is that autostart[.sh] is run by /bin/sh not by bash. If you're trying a tricky command it might work with bash but not with sh, which is less sophisticated. Try typing sh in your terminal before running the command. If you need bash you can put the command in a script and run that instead.)

This also means that you may need to specify the full path to a script, rather than using a bash shortcut like ~ for your home folder.

But I did!

Well, then it was run but not properly displayed. That means that you have to execute the program a few seconds after the rest of the script. which brings us to…

The sleep invocation!

Some programs don't like to wake up at the same time as everybody else, just like some humans like to sleep longer than other people and gets grumpy if they're awakened too early, or before another program they depend on is ready. We can avoid this problem by using by the sleep invocation. This is actually a quite well-named program, it delays the execution of a command by a certain amount of time (the program sleeps before it's awakened).

For example:

# application_description and is executed 3 seconds after the script is run.
(sleep 3s && application_command) &
  • Everything has to be within the parentheses, (except the final '&').
  • 'sleep 3s' delays the following command for 3 seconds.
  • '&&' makes everything written behind wait until the sleep invocation is run.
  • 'application_command' executes the application as before.
  • The '&' in the end makes sure that it doesn't freeze, and also makes sure that all programs written beneath is not run after the sleep as well (faster startup).

Hmm, cool, can I just type in any script I want to run?

Yes you can, just see if you can execute it successfully from the terminal and everything is fine (though if you have some big heavy bastards they will slow down the startup).

Programs? I have programs? Where?

You can find most of the commands in the '/usr/bin/' folder if you need more pointers on what a program does, or you need it to perform in another way, type 'man application_command' in the terminal and see if you find something that's your cup of tea.

Tip

Test commands in the terminal first, if they work there they will probably work in your autostart file, and if they don't they are easier to debug.

And the final test if it works

Restart or re-login to your computer.

Autostart applications when XFCE starts

To perform the above in xfce edit the following file instead:

~/.config/xfce4/autostart.sh

Links

 
howto/autostart_programs.txt · Last modified: 2012/06/15 22:15 by pidsley
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Share Alike 3.0 Unported

Powered by DokuWiki. Hosted by Linode.
Copyright © 2010 CrunchBang Linux.
Proudly powered by Debian GNU/Linux.
Debian is a registered trademark of Software in the Public Interest, Inc.