I want to have some files in the home directory, that can cause applications to be started inside any X, Wayland, or similar session, automatically (with no user intervantion), at the beginning.
I have heard of some ways to do this, but only under very restricted conditions, or to do not quite this, but only something similar.
A few examples for other software that has autostart functions:
So bash has .bashrc, .bash_profile, etc, and all the shells have equivalent files. One or more of the files run at the beginning of bash, setting environment variables, run programs. Then, bash is ready to use.
There seems to be no such thing in X11. There are a lot of files - .xinitrc, .xsession, .Xclients, .xprofile, that have a similar function, but not the same. It usually, but not always, seems to be, for each file:
- The "session" or whatever, may or may not look at the file.
- The following steps may or may not apply, or something different may apply.
- If the file is executable, the normal X session will not be started, but some files may be executed first.
- If the file is executable, it will be started.
- If (when) the execution of the file terminates, the X session terminates.
Instead, one is supposed to put something like gnome-session, or fluxbox, or twm, at the end of the script. Without an "&"! Then no matter what session is started (Gnome, KDE, fluxbox, ...), the named thing will not come up of course, but only the last line in the .xwhateverrc.
Also, everything is "may or may not". I didn't try most of these things recently, it's just a waste of time. I read some files instead:
/etc/X11/Sessions/Xsession handles .xsession and .Xclients in this way.
/etc/X11/Sessions/Gnome handles .gnomerc in this way.
/etc/gdm/Xsession handles .Xclients in this way, and mentions .xsession in comments, and handles .xprofile as a real "autostart inside X".
/etc/X11/Sessions/icewm does nothing of this - maybe the icewm-session command does.
It all depends on the specific display manager (xdm replacement) and on the chosen session. But for most files, if they are present, they can only replace the session altogether. .xprofile is an exception, and does what I want at least in some cases.
That means - if you would e.g. create a working .xsession or .Xclients, and make it work for Gnome, you can't run anything else (with exceptions). And after an update, the name of the command to call as the last line may change to gnome-future, and gnome-session will no longer work.
For .xprofile it may depend on the display manager/session combination. I don't know. One must adapt the file to the calling mode, which is unknown. If it is wrong, then nothing will run at all, or after logout a second session will run immediately.
I make sure no such files exist. Instead I have a script in ~/bin. Years ago, I could start it from a Gnome Autostart feature. But in the new Gnome, this is no more. Instead, for a long time, it was ... again ... a "may or may not" thing. So I found that in recent Gnome, it is not possible to autostart arbitrary scripts. There was a .desktop file in .config/autostart (I made that 2) which recently stopped working. There was even a .desktop file in .config/autostart-scripts/ which worked for a while, but does no more. Autostarting is now restricted to a list of preapproved applications (maybe with a .desktop file in nobody knows where).
So I developed a workaround. I added a new terminal to autostart, in this case "lxterminal" (just not Gnome Terminal). This does start an lxterminal in a new session. Then I manipulated its .desktop file in the autostart folder, to exec "lxterminal -e ~/bin/myscript". This never worked, because ~ would not be expanded. So I changed it to "lxterminal -e sh -c '~/bin/myscript'". Only this expands the ~.
The script itself is heavily guarded to not run recursively, not run concurrently, and run just once even if called many times.
I also noted that Gnome autostarts a lot of stuff that is not in autostart. It seems this includes stuff dropped in some "session" directory, and executable .desktop files in /etc/xdg/autostart/. (In other places, it does not matter whether .desktop files are executable). It actually resembles malware behaviour. (Start it once, and it never again goes away)
But, is there any kind of standard so I can improve this.
For example, is the calling mode of .xprofile and others standardized, so that it either always runs inside, and not instead of the session, or always instead of, and not inside the session?
And what mechanisms exist to autostart something inside a gnome session? I know there is more than .config/autostart and (possibly) .config/autostart-scripts/.
Are any mechanisms known for other DEs?

