Results 1 to 8 of 8

Thread: HOWTO: Set Sessions Startup Order

  1. #1
    Join Date
    Jan 2007
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Lightbulb HOWTO: Set Sessions Startup Order

    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:
        Code:
        gnome-session-properties
    • 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.
    Code:
    bash -c "sleep X; /path/application"
    Example: bash -c "sleep 20; gimp"

    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:
    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

    [Desktop Entry]
    Type=Application
    Name=gimp
    Exec=bash -c "sleep 40; /usr/bin/gimp"
    Icon=system-run
    Comment=This is a comment I entered.
    Note: Each .desktop file contains a blank first line. The files are not marked as executable and are owned by the $HOME owner.

    9. Acknowledgments
    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.
    GRUB2

    Retired.

  2. #2
    Join Date
    Jun 2007
    Beans
    Hidden!

    Re: HOWTO: Set Sessions Startup Order

    When you were looking through the .desktop files did you notice the x-gnome options? I find these to be more effective in setting the order.

    Code:
    Type=Application
    Name=GNOME Settings Daemon
    Exec=/usr/lib/gnome-settings-daemon/gnome-settings-daemon
    OnlyShowIn=GNOME;
    X-GNOME-Autostart-Phase=Initialization
    X-GNOME-Autostart-Notify=true
    X-GNOME-AutoRestart=true
    X-Ubuntu-Gettext-Domain=gnome-settings-daemon
    so far the phases I've been able to figure out are; Initialization, Desktop, Panel, and Applications. kde has similar options worded differently. I would suggest using sleep in the exc only be used in the application phase and only sparingly because each second you add with sleep, adds to your over all startup time.

  3. #3
    Join Date
    Oct 2008
    Beans
    206
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: HOWTO: Set Sessions Startup Order

    i was able to locate the individual files in the autostart folder, and want to make firestarter delay by about 30 sec, because i always get an error message since firestarter starts before my internet connection is established....

    so where does this bash command belong, in the file ? when i open the file, the first entry is red, the rest of the items are green, should i add the bash command at the top or at the end ?

    while on this topic...i'd like to make firestarter start minimized to the panel, is that possible ?
    HP Envy 17
    ubuntu 10.10 kernel 2.6.37
    windows 7

  4. #4
    Join Date
    Jan 2007
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: HOWTO: Set Sessions Startup Order

    Quote Originally Posted by zero7404 View Post
    i was able to locate the individual files in the autostart folder, and want to make firestarter delay by about 30 sec, because i always get an error message since firestarter starts before my internet connection is established....

    so where does this bash command belong, in the file ?
    I installed firestarter, added it to Sessions/Startup Applications, and checked the autostart file. Open the firestarter.desktop file with:
    Code:
    gedit $HOME/.config/autostart/firestarter.desktop
    Note: the file may just be called "firestarter", in which case substitute this for "firestarter.desktop"

    Then edit the line as indicated. You may have to experiment to see what type of delay you need.
    (Added later: See post #6 for modified command to account for root privileges.)
    Code:
    [Desktop Entry]
    Type=Application
    Name=fs
    Exec=bash -c "sleep 30; /usr/sbin/firestarter"
    Icon=system-run
    Comment=
    Last edited by drs305; April 27th, 2009 at 03:56 PM. Reason: firestarter vs firestarter.desktop
    GRUB2

    Retired.

  5. #5
    Join Date
    Oct 2008
    Beans
    206
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: HOWTO: Set Sessions Startup Order

    thanks,

    i changed the entry in the file, but on restart, i get an error saying i don't have privileges to start firestarter....

    there used to be the entry gksu /usr/sbin/firestarter....
    the new bash entry doesn't contain gksu or other superuser command...
    HP Envy 17
    ubuntu 10.10 kernel 2.6.37
    windows 7

  6. #6
    Join Date
    Jan 2007
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: HOWTO: Set Sessions Startup Order

    Since firestarter apparently needs admin privileges to run, you can insert "gksu" in the startup command. When I tried this, a password message appeared after the delay and asked me to insert it. Firestarter then ran normally.

    Change the line in $HOME/.config/autostart/firestarter.desktop to:
    Exec=bash -c "sleep 30; gksu /usr/sbin/firestarter"
    Last edited by drs305; April 27th, 2009 at 03:40 PM. Reason: moved "gksu"
    GRUB2

    Retired.

  7. #7
    Join Date
    Oct 2008
    Beans
    206
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: HOWTO: Set Sessions Startup Order

    works great now, thanks !
    Last edited by zero7404; April 27th, 2009 at 03:46 PM.
    HP Envy 17
    ubuntu 10.10 kernel 2.6.37
    windows 7

  8. #8
    Join Date
    Nov 2006
    Location
    Boston
    Beans
    1,036

    Re: HOWTO: Set Sessions Startup Order

    Quote Originally Posted by drs305 View Post
    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.
    Code:
    bash -c "sleep X; /path/application"
    Example: bash -c "sleep 20; gimp"

    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.
    Thank you for these instructions. I've been wanting to find a well-explained method for creating a pause before launching Google Gadgets Sidebar so it opens after Compiz and AWN. For the first time since I started using the Sidebar I don't have those ugly borders around my gGadgets. I definitely owe you a few beers for even these few paragraphs.

    You rock!
    For an OSX look check out Mac4Lin (updated support thread)
    Follow me on Twitter | My Blog
    The Search tool is your friend.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •