Wednesday, July 5, 2017

GNOME Startup Application

Simply put, a GNOME Startup Application is a script or binary file that is execute upon the GNOME Desktop launch, more specifically, as part of the gnome-session establishment. The gnome-session connects to the X infra-structure at which point X resources become availble to the session and its children.

The startup applications should be used to startup things that require (or are desired upon) a graphical desktop or X infrastructure already running. That's the main purpose and difference from other more familiar startup files such as /etc/profile and .profile.

For instance, setting a GNOME Startup Application may be the only solution to autostart a virtual machine only upon logging into the desktop GUI. Note that this is different from the intrinsic VirtualBox Autostart feature.

The GNOME Startup Applications feature follows the FreeDesktop.org Specifications, topic Autostart specification, preferably the latest. Basically, a file with the extension .desktop has to be create at ~/.config/autostart/ or at /etc/xdg/autostart/ respectively to a single user or all users. The local directory has higher precedence in case of equally named files in both places. Furthermore, both these search locations could be respectively customized by setting $XDG_CONFIG_HOME and / or $XDG_CONFIG_DIRS.

The easiest way setting it is through the GUI itself via the menu sequence System | Preferences | Startup Applications or by invoking the command
gnome-session-properties, both of which invoke the same dialog:


By clicking the Add button one configures another entry, such as:


Getting the following as a result:


Alternatively, you can create yourself the file with the following contents:

$ cat .config/autostart/zenity.desktop

[Desktop Entry]
Type=Application
Exec=zenity --about

Hidden=false
X-GNOME-Autostart-enabled=true
Name[en_US]=Zenity
Name=Zenity
Comment[en_US]=The Zenity about box
Comment=The Zenity about box


The above file content can be greatly customized.
For instance, depending on the situation, add: Path and Terminal.
For the details, better check the following: Desktop Entry Specification.

During logon, the example above will display the following dialog at or near (0,0), the top-left corner, as there's no parent window for it to center in (the application should position itself, support the --geometry argument or something similar to that):


By looking at Zenity maintenance page, there's no plan to address centering:


It may be convenient to have certain executable shell scripts being launched by this tool as well, but there's one gotcha about the Exec key and the .desktop file: environment variables are not directly supported. Hence, to launch the script ~/.autostart-script1 the following is required:

$ cat .config/autostart/.autostart-script1.desktop

[Desktop Entry]
Type=Application
Exec=bash -c "$HOME/.autostart-script1" --
Hidden=false
X-GNOME-Autostart-enabled=true
Name[en_US]=Script1
Name=Script1
Comment[en_US]=Test script #1
Comment=Test script #1