HOWTO: SET SESSIONS STARTUP ORDER
In a Rush? Go Directly to #6 for the codes to enter in the Sessions command line.
1. Purpose and Background:
Sessions allows Ubuntu users to specifiy applications they wish to run on logon. This guide presents information on how to incorporate delay codes into the Sessions commands to start the applications in a relatively pre-determined order. Sessions has been renamed Startup Applications in Jaunty Jackalope 9.04.
Often Ubuntu users want to delay the opening of a process listed in Sessions. Attempting to make a direct entry into the Sessions command line of "sleep 20 && /path/<appname>" does not work. A common workaround was to create a BASH script which includes the sleep command and reference that script in the Sessions entry.
With the proper formatting a user can include a delay period within the Sessions-generated command itself. This offers a more direct method, via a gui application, and avoids having to create a BASH script. Reasons for wanting to input delays before an application run command include:
- Allowing another application to start first (or second, third, etc).
- Wanting to place the icons in a particular order on the panel's Window List.
3. The Mechanics.
The tasks accomplished by Sessions should not be confused with runlevel actions performed by the system on entries in the /etc/init.d folder during boot. Sessions applications begin after the user logs on - thus they are specific to each user and do not require 'root' privileges to accomplish "non-root" tasks.
When an addition is made to the Sessions menu, a configuration file is made in $HOME/.config/autostart folder *. The .config folder is "hidden". If you do not see it in a file browser, CTRL-H to view hidden files or use the application's Preferences menu to enable viewing them. The file is created with the extension .desktop and the contents are determined by what the user enters when creating a new startup item.
* Note: "$HOME" denotes the user's HOME folder, and can also be designated as ~/ or as /home/username/. So the path to the file could also be written as /home/username/.config/autostart.
4. Determining the Run Command
Before proceeding you first must know what command starts the application. Some, such as "gedit", may seem obvious. Others may seem obvious but require certain switches to perform properly in Sessions (See nautilus in Section 7). Others are just not obvious, such as the calc function of OpenOffice (oocalc).
- Check the properties of the application's shortcut icon.
- If you already have a shortcut a panel or the Desktop, right click the shortcut icon, select Properties, and view the Command: entry.
- If the application appears within the Main Menu, open the menu for editing: Right click the Main Menu icon, Edit Menus. Select the appropriate category in the left panel, then highlight the application appearing in the right panel. Select Properties to display the run command.
- If you think you know the correct name, type "which <appname>" in a terminal.
This will return the start command and its path.
Example: which gimp returns /usr/bin/gimp
- Look in Synaptic. Find the application, highlight it, and select Properties in the top menu. Click on the "installed files" tab and look for a run command. Again, the path /usr/bin is a good place to start.
Example: OpenOffice calc. /usr/bin/oocalc
- Search the forums or internet in general. Including the common name and "command" or "run command" will generally provide useful search results.
- Note: Some application files end with the version number as part of the filename. If so, try running the command without the ending version number. If it opens the correct version, omit it. If it opens the wrong version or doesn't run, include these in the run command. Omitting the version number may allow the script to run without modification when the application version number changes with an upgrade.
Example: gimp-2.6 and gimp both work. Use gimp for future version compatibility if possible.
Once you have the command, test it in a terminal window and make sure the application launches properly. Trying to add a delay code to a command that doesn't work on the command line will make troubleshooting more difficult.
5. Creating a Sessions Listing
- Open the Sessions dialog box:
- From the Main Menu: System > Preferences > Sessions (renamed Startup Applications in Jaunty). Select "Add +"
- From the command line:
- Enter a name for the entry. This is the name which will appear in the Sessions menu. See Note 1.
- Enter the command. You can use the "Browse ..." button to the right of the command box to search for and select for the application's run command. Often this command is found in the /usr/bin folder. It is preferable to include the complete path to the command to prevent PATH errors.
- Enter a comment if desired.
- Select "Add+" to create the file.
- Note 1: The name entered in Sessions may not generate the same name in the .desktop file. The $HOME/.config/autostart/*.desktop file might start with gnome, bash, etc and may not even contain the name you entered in the Sessions name window. You don't really need to know the name to use it. If you want to view the file and don't see it listed in $HOME/.config/autostart look for the newest file. You can also probably locate a .desktop file by searching the autostart folder for files created within the last 5 mintues using this command: "find $HOME/.config/autostart -type f -cmin -5"
The files are simple text files that can be opened with a text editor.
6. Adding a Startup Delay
To correctly process a delay code including the sleep command, the entry should be made in the following format. Replace X with the number of seconds you want to delay the start.
Example: bash -c "sleep 20; gimp"Code:bash -c "sleep X; /path/application"
Note The delay time may need to be adjusted to ensure an application is started before or after another one. Timing begins after the user logs in, but different applications have different initialization times. A complex program may start first but open long after a simpler program with a longer sleep delay. It may be necessary to adjust the time values to obtain the desired results. [/LIST]
To test the new Sessions entries, you must log out and log back in. Rebooting is not necessary.
7. Switches and Special Commands
Some commands will open an application normally in a terminal but will not open the same program via the Sessions script. This generally involves applications which require special switches or additions when opened in this manner. If you have difficulty in getting a particular application to start, check the "man" page and look at the available options.
I will expand this section as relatively common applications needing these switches are brought to my attention.
nautilus is not just a file browser, it is a file manager. The command nautilus controls several important gnome processes. To use the command as a file browser include a PATH following the command. This ensures the nautilus file browser is started. Failure to include a path may result in the command running but not opening a browser window.
Code:bash -c "sleep 10; nautilus $HOME" or: bash -c "sleep 10; nautilus /media/mydata"
8. A Sample SESSIONS .desktop File:
This is a file created by Sessions to start gimp with a delay of 20 seconds. The gimp run command is "/usr/bin/gimp". The file, once created, was located at /home/username/.config/autostart/gimp.desktop
Note: Each .desktop file contains a blank first line. The files are not marked as executable and are owned by the $HOME owner.
Exec=bash -c "sleep 40; /usr/bin/gimp"
Comment=This is a comment I entered.
The guide was prepared following discussions which began on this thread: Set session startup order ? by RavanH.
The thread evolved and was expanded by plamen_todoroff. Several different methods were discussed and this HOWTO is the result of those discussions. Thanks to all who participated and contributed in that thread.