How can I run a command automatically when I login?

In other distros, I’ve simply pasted a command that I want to run automatically into ~/.profile, but that doesn’t seem to work on fedora. Am I doing something wrong? My ~/.profile file is as follows:

gsettings set disable-user-extensions true && gsettings set disable-user-extensions false

(as a side note, I’m running this command because if I don’t disable and re-enable the appindicators extension, my appindicators don’t show up properly)

Hello and welcome!

It appears you are using the Workstation version with gnome. If so then you may need to install both packages gnome-tweaks and gnome-extensions-app. Once that is done then use the gnome-tweaks and with the portion in the image below you can easily set apps that will startup automatically as soon as you log in.

Thanks for the reply! I have gnome-tweaks and use it to run applications at login, but as far as I can tell, there doesn’t seem to be a way to run custom commands with it.

I guess I could make a .desktop file with the command I want to run, but that seems like kind of a roundabout solution. I was hoping there would be something more straightforward.

I just tried making a .desktop file for it, but it doesn’t work at all either.

[Desktop Entry]
Name=reload extensions
Exec=gsettings set disable-user-extensions true && gsettings set disable-user-extensions false

I figured it out - the command needs to be run through sh not exec. Exec gets confused by having more than one command in a row.

[Desktop Entry]
Name=reload extensions
Exec=sh -c “gsettings set disable-user-extensions true && gsettings set disable-user-extensions false”

If bash is your default shell then .bash_profile is executed once on log in.

Your first command is redundant since the second one just overwrites it.

I thought that bash_profile was just for logging into a terminal session, not for GUI login?

I’m aware. The intent is to disable and then re-enable the gnome extensions on login because doing so fixes a bug in the appindicators extension.

See Improper Mullvad Tray Icon · Issue #4798 · mullvad/mullvadvpn-app · GitHub

Good morning. I do not know for sure when .bash_profile is sourced. My understanding is that gnome terminal sessions are not login sessions so ,bashrc is sourced but not .bash_profile. But exactly when .bash_profile is sourced is unclear. Some time with google search this morning and yesterday did not really yield a solid answer. :slight_smile:

As I understand it, if you were to use a terminal to log in (ctrl-alt-F3 or similar) then .bash_profile is used, but not otherwise. I am not 100% certain though since the default content of .bash_profile seems to be this and matches what is in my user home directory.

$ cat /etc/skel/.bash_profile 
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
    . ~/.bashrc

# User specific environment and startup programs

The use of systemd is quite flexible. There is a lot systemd supports at the user level.

I did not find a fedora link but I did find this:

The use of systemd for running what used to be done with cron jobs as a regular user is also quite nice.

1 Like