Linux: Auto Start Script / Application when Login
Below will guide how to run script or start app when login.
This is useful for config key binding or open frequently used app.
Different level of “Start”
- Boot → Systemd — run when the system start
- Terminal →
.bash_profile
,.bashrc
,.zshrc
etc. run when open the terminal - GUI desktop → X session
.xsession
,.Xclients
,.xinit
this is but note that this is not run on its own - Window Manager → e.g. GDM /LightDM etc.— this is the manager to manage X session
Boot is too early.
Terminal is not necessarily open when login.
GUI Desktop is not on its own.
Window Manager is the Level we’re looking for
Here are the steps to config the file
- File location:
~/.config/autostart/
- Naming:
xxxxx.desktop
- Format: see sample below
Example: Start Google chrome application
[Desktop Entry]
Type=Application
Encoding=UTF-8
Name=Terminal
Comment=Terminal
Exec=google-chrome
Terminal=false
Type=Application
Encoding=UTF-8
Name=Terminal
Comment=Terminal
Exec=google-chrome
Terminal=false
Example: Start “myinitscript.sh”
[Desktop Entry]
Type=Application
Encoding=UTF-8
Name=Keybinding
Comment=Tanut key binding
Exec=bash -c "source ~/myinitscript.sh"
Terminal=false
Type=Application
Encoding=UTF-8
Name=Keybinding
Comment=Tanut key binding
Exec=bash -c "source ~/myinitscript.sh"
Terminal=false
Cheers !