Autostarting scripts

Hello everyone,
I have a few questions about running scripts and apps on startup of gnome.
First of all I have custom key mapping which I can start with xmodmap ~/.Xmodmap command.
But it isn’t autostarting so I made a .desktop entry in /home/ryxwaer/.config/autostart.

[Desktop Entry]
Exec=xmodmap ~/.Xmodmap

Unfortunately it isn’t working. Is there something what I amd doing wrong?
Also is there a way to execute bash script at startup? I am autostarting TeamViewer with .desktop entry but it always opens the TeamViewer window and I can not seem to find a way to start it hidden. So I decided to write a script to close it:

sleep 1
wmctrl -c "TeamViewer"

Then I try to execute it with .desktop entry:

[Desktop Entry]

But nothing happens.
I am looking forward to your ideas. Thanks.

Hi @ryxwaer,

While I don’t use Gnome, I did a quick search about running something on startup, finding:

Open Startup Applications via the Activities overview. Alternatively you can press Alt + F2 and run the gnome-session-properties command. Click Add and enter the command to be executed at login (name and comment are optional).

Regarding TeamViewer, that looks like quite the hacky workaround. It would be better to start it minimized, or in the background. So I did another bit of googling finding this page, where a user states:

Open Teamviewer then click Connection, Setup unattended access. I think that’s what you’re asking for.

So try that.

Hope it helps!

1 Like

Hello. I know how to use google. I am trying to resolve this issue for a few days.

  1. This command isn’t working. I am accessing startup application with gnome tweaks and I can clearly see my xmodmap.desktop here because I have it located in ~/.config/autostart. Everything there is executed at startup except this file. So I am asking if there is something wrong with the way I wrote .desktop file.
  2. This article is 6 years old. Teamviewer isn’t the same anymore. From the teamviewer documentation I found that it should be started hidden automatically if it is executed by system. It was working under KDE Plasma but not under gnome so I was pushed to this ugly workaround. But I hope there is better solution that is also working.

Well, in this .desktop file,

What I can see quickly, is that there is no script/application specified at Exec=. This line,


should actually be

Exec=sleep 1 && wmctrl -c "TeamViewer"

I think. Or else the full path to your script:


But for that to work you have to be sure that the script works manually.

Note: Make sure, if you use the script route, that you set the script as executable:

chmod +x /full/path/to/

Hope this is more what you were looking for.


For further reading: Desktop entries - ArchWiki

I validated my .desktop files with desktop-file-validate command. I found some deprecated lines and deleted them. Unfortunately they still don’t work.
My edited xmodmap.desktop:

[Desktop Entry]
Exec=/usr/bin/xmodmap "/home/ryxwaer/.Xmodmap"

I added .sh to the absolute path to my script file in exec line in scripts.desktop:

[Desktop Entry]

I also added .sh to the script file itself :smiley:

sleep 1
wmctrl -c "TeamViewer"

Any more ideas ?

Well, after some more searching, I came across this page that states:

The correct place to put xmodmap ~/.Xmodmap (so that your changes are read at startup) is in ~/.xinitrc (see explanation below), although you could alternately place the xmodmap command as a startup item (/usr/bin/xmodmap /home/user/.Xmodmap). I can say that for 12.04 (and presumably 12.10) that these two alternatives definitely do work, as either way they are read after you log in with lightdm. (I changed Return to Right Shift, and the change only took effect after entering my password and logging in).

So that might help.

Also, please provide the output of:

stat /home/ryxwaer/.config/autostart/


Teamviewer uses systemd to start the service, has to be enabled, and has its own way to enable startup when system starts.
Gnome has a proper example file how to autostart applications. Please check those.

1 Like

I already tryed to add it in ~/.xinitrc but it done nothing. This is it:

# ~/.xinitrc
# Executed by startx (run your window manager from here)



# merge in defaults and keymaps

if [ -f $sysresources ]; then
    xrdb -merge $sysresources

if [ -f $sysmodmap ]; then
    xmodmap $sysmodmap

if [ -f "$userresources" ]; then
    xrdb -merge "$userresources"

if [ -f "$usermodmap" ]; then
    xmodmap "$usermodmap"

# start some nice programs
xmodmap ~/.Xmodmap

if [ -d /etc/X11/xinit/xinitrc.d ] ; then
    for f in /etc/X11/xinit/xinitrc.d/?*.sh ; do
        [ -x "$f" ] && . "$f"
    unset f

	local dbus_args=(--sh-syntax --exit-with-session)
	case $1 in
		awesome) dbus_args+=(awesome) ;;
		bspwm) dbus_args+=(bspwm-session) ;;
		budgie) dbus_args+=(budgie-desktop) ;;
		cinnamon) dbus_args+=(cinnamon-session) ;;
		deepin) dbus_args+=(startdde) ;;
		enlightenment) dbus_args+=(enlightenment_start) ;;
		fluxbox) dbus_args+=(startfluxbox) ;;
		gnome) dbus_args+=(gnome-session) ;;
		i3|i3wm) dbus_args+=(i3 --shmlog-size 0) ;;
		jwm) dbus_args+=(jwm) ;;
		kde) dbus_args+=(startplasma-x11) ;;
		lxde) dbus_args+=(startlxde) ;;
		lxqt) dbus_args+=(lxqt-session) ;;
		mate) dbus_args+=(mate-session) ;;
		xfce) dbus_args+=(xfce4-session) ;;
		openbox) dbus_args+=(openbox-session) ;;
		*) dbus_args+=($DEFAULT_SESSION) ;;

	echo "dbus-launch ${dbus_args[*]}"

exec $(get_session "$1")

Output of stat /home/ryxwaer/.config/autostart/ :

  File: /home/ryxwaer/.config/autostart/
  Size: 89        	Blocks: 8          IO Block: 4096   regular file
Device: 259,7	Inode: 4743614     Links: 1
Access: (0755/-rwxr-xr-x)  Uid: ( 1000/ ryxwaer)   Gid: ( 1001/ ryxwaer)
Access: 2021-11-19 23:25:26.543340000 +0100
Modify: 2021-11-19 23:29:38.086679426 +0100
Change: 2021-11-23 17:58:13.274050499 +0100
 Birth: 2021-11-19 23:25:26.543340689 +0100

Thanks. You was right. All I had to do was enable autostart in TeamViewer settings. I wasn’t expecting it to work so I ignored that setting :smiley:
But my biggest concern is still the Xmodmap which should also work without autostarting script.

But if you are on wayland, almost nothing with X11 in “mind” will run …

Nah wayland isn’t good for me I had to switch to the Xorg like first day I installed manjaro gnome on my laptop.

Moderator Edit: Removed useless potato photo of a screen. Take a screenshot next time.

So I managed to find a workaround. It is working only if I call xmodmap ~/.Xmodmap from .sh script executed by .desktop file on startup. But there is yet another thing! It is working only if script wait at least 3 seconds before executing xmodmap ~/.Xmodmap. So when my laptop boots up I am stuck with black screen for about 10 seconds until the script successfully ends.
Is there a way to speed this process up ?