Auto-start programs using Terminal F37

Fedora 37 does not have a Startup Applications program, as does Ubuntu, and not that anyone has asked but I was able to autostart a program with a terminal command by altering the Exec line in the *.desktop file.

First, I used Gnome Tweaks > Startup Applications to auto-start the Terminal. Then I edited the file ~/.config/autostart/org.gnome.Terminal.desktop file as follows:

The Exec line read:
Exec=gnome-terminal
to which I appended '-e “protonvpn-cli c -f” ’ which happens to be the command to start protonvpn. The -e switch tells terminal to execute the argument which follows in quotation marks. The line now reads:

Exec=gnome-terminal -e “protonvpn-cli c -f”

You can actually customize startup applications with GNOME Tweaks.
However, note that the app intended to run as a service attached to the user session is best implemented with a systemd user unit.

1 Like

If you need a terminal command to run when you login, that’s what the .bashrc and .bash_profile in your home directory are for. And as @vgaetera says, systemd user units are there for that purpose too.

First you create either ${HOME}/.local/share/systemd/user/ or ${HOME}/.config/systemd/user/, drop your unit files into it, then run systemctl --user daemon-reload. Then you can start / stop / enable / disable it with systemctl --user whatever

I’m not sure. They will eventually start something when you open a shell, I don’t think they are used when you login to a graphical environment. Or I’m wrong?

I think you are quite right. .bashrc is only read when opening an interactive terminal. However, .profile, or, as used in Fedora, .bash_profile can be used (bash will only read .profile if there is no .bash_profile). These are read for a login shell.

It is perfectly fine as well to start terminal commands in the background using a .desktop launcher as well. There is no need to start gnome-terminal unless it is a program you want to interact with.

systemd indeed is a proper approach, but a bit more complicated (although probably not that much for simple tasks).