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]
Type=Application
Encoding=UTF-8
Name=Xmodmap
Exec=xmodmap ~/.Xmodmap
Terminal=false
StartupNotify=false
Categories=Application;
X-GNOME-Autostart-enabled=true

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:

#!/bin/bash
sleep 1
wmctrl -c "TeamViewer"

Then I try to execute it with .desktop entry:

[Desktop Entry]
Type=Application
Name=Scripts
Exec=/home/ryxwaer/.config/autostart/scripts
Terminal=false
StartupNotify=false
Categories=Application;
X-GNOME-Autostart-enabled=true

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,

Exec=/home/ryxwaer/.config/autostart/scripts

should actually be

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

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

Exec=/full/path/to/hide-script.sh

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/hide-script.sh

Hope this is more what you were looking for.

Edit:

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]
Type=Application
Name=Xmodmap
Exec=/usr/bin/xmodmap "/home/ryxwaer/.Xmodmap"
Terminal=false
StartupNotify=false
X-GNOME-Autostart-enabled=true

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

[Desktop Entry]
Type=Application
Name=Scripts
Exec=/home/ryxwaer/.config/autostart/scripts.sh
Terminal=false
StartupNotify=false
X-GNOME-Autostart-enabled=true

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

#!/bin/bash
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/scripts.sh

Hello,

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:

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

userresources=$HOME/.Xresources
usermodmap=$HOME/.Xmodmap
sysresources=/etc/X11/xinit/.Xresources
sysmodmap=/etc/X11/xinit/.Xmodmap

DEFAULT_SESSION=gnome-session

# merge in defaults and keymaps

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

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

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

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

# 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"
    done
    unset f
fi

get_session(){
	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) ;;
	esac

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

exec $(get_session "$1")

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

  File: /home/ryxwaer/.config/autostart/scripts.sh
  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 ?