Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

sudo nano /etc/xdg/lxsession/LXDE-pi/autostart

Tue Jul 07, 2015 1:59 am

I want to add an autostart item to my desktop (startx). The above mentioned command seems to be the Frequently Given Answer to this question.

However, editing a root-owned global file to do user configuration is hardly the Unix way. It seems more likely that one should be editing a file under one's $HOME.

So, my questions are:
  1. What is the equivalent file under ~/.config that I can edit?
  2. Is there a way to do this (add "autostart" items) directly via the GUI (without doing any file editing) ?
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

JimmyN
Posts: 1109
Joined: Wed Mar 18, 2015 7:05 pm
Location: Virginia, USA

Re: sudo nano /etc/xdg/lxsession/LXDE-pi/autostart

Tue Jul 07, 2015 9:58 pm

LXDE autostart for an individual user is located at
/home/<username>/.config/lxsession/LXDE/autostart

The "lxsession" and "LXDE" directories probably don't exist, so just create them. I use that method, because I sometimes log in as a different user and want a different autostart, or possibly none at all.

I don't know of any way to add to autostart entries using the GUI, other than Leafpad. Technically that's sort of using the GUI :mrgreen:

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: sudo nano /etc/xdg/lxsession/LXDE-pi/autostart

Tue Jul 07, 2015 10:25 pm

Thank you for responding. See, the thing is, there's so many directories, with subtly different names and such. I could probably figure this out by trial-and-error, but I'd rather not do that. I'd like a definitive answer (especially because the only way to test it is to reboot, and that's time-consuming). Part of the confusion is between LXDE and LXDE-pi.

For starters, 'ps' tells me that 'lxsession' running with -s and -e options set like this:

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
pi 2691 0.0 0.3 12876 2988 tty2 Sl Jun26 1:28 /usr/bin/lxsession -s LXDE-pi -e LXDE

I found something on the web that tells me what -s and -e are, but it didn't make much sense.

Now, on one system, installed c. Feb 12, 2015, I look in ~/.config/lxsession and I see a LXDE directory (only). On another system, more or less identical, but installed later (c. April 21, 2015), I see (in the same directory) LXDE-pi (only). This, of course, doesn't give me a good feeling. Which one is right?

And, more importantly, how does one know?
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: sudo nano /etc/xdg/lxsession/LXDE-pi/autostart

Tue Jul 07, 2015 10:26 pm

P.S. Yeah, I had a look around - and there doesn't seem to be any "GUI way" to set this up. Shame, that.

(Good line about using leafpad being sorta GUI. heh heh)
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: sudo nano /etc/xdg/lxsession/LXDE-pi/autostart

Tue Jul 07, 2015 10:30 pm

And, one other question. Assuming that one is able to find and edit the right file, and one is able to setup one's own autostart entries, is that file treated as "in addition to" the system files (the ones in /etc/xdg) or does it replace them?

Logically, "in addition to" is the only sensible choice, but every once in a while, in the Unix scheme of things, I find instances where the "replace model" is in effect. What this means is that the moment you create and start using your own file, you lose the benefits of the system-wide file.

I'm praying that's not the case here...
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

JimmyN
Posts: 1109
Joined: Wed Mar 18, 2015 7:05 pm
Location: Virginia, USA

Re: sudo nano /etc/xdg/lxsession/LXDE-pi/autostart

Wed Jul 08, 2015 12:47 am

It used to be /etc/xdg/lxsession/LXDE/ but it changed a while back, probably during one of the desktop upgrades, and started using /LXDE-pi/. So you could have either one depending on which version you're running. Obviously the users autostart is not there by default, but you can add it.

I don't know this for a fact, but logically the /etc/xdg/ file would be read first, then the user profile after the login. Generally user settings take precedence over system settings and are applied last. But if you ran a binary or script in the desktop startup, and then started it again when the user logged in there could be some issues. But that's not hard to deal with, when you create the shell script to put in the users autostart write it so that it kills the process first, then starts it. If it's not running, no harm, no foul. If it was running it's safe to start it again.

For instance I use this one to start Synergy

Code: Select all

#!/bin/bash

killall synergyc
sleep 1
synergyc --name Rpi 192.168.0.3
exit 0
If it's running club it, wait a moment for it to expire, then revive it.

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: sudo nano /etc/xdg/lxsession/LXDE-pi/autostart

Wed Jul 08, 2015 3:31 am

I'm still not convinced that one can say authoritatively which one to use.

Why does the lxsession program use both - one as the arg to -s and the other as the arg to -e (on the same command line) ?

And for even more giggles, observe this:

Code: Select all

$ ls -lsa /etc/xdg/lxsession/*
/etc/xdg/lxsession/LXDE:
total 16
4 drwxr-xr-x 2 root root            4,096 Dec 31  1969 ./
4 drwxr-xr-x 4 root root            4,096 Dec 31  1969 ../
4 -rw-r--r-- 1 root root               83 May 18  2012 autostart
4 -rw-r--r-- 1 root root              299 Feb 16 08:22 desktop.conf

/etc/xdg/lxsession/LXDE-pi:
total 16
4 drwxr-xr-x 2 root root            4,096 Dec 31  1969 ./
4 drwxr-xr-x 4 root root            4,096 Dec 31  1969 ../
4 -rw-r--r-- 1 root root               89 Nov 17  2014 autostart
4 -rw-r--r-- 1 root root              481 Nov 17  2014 desktop.conf

Total: 17,336
$ 
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

JimmyN
Posts: 1109
Joined: Wed Mar 18, 2015 7:05 pm
Location: Virginia, USA

Re: sudo nano /etc/xdg/lxsession/LXDE-pi/autostart

Wed Jul 08, 2015 11:11 am

Looks like I was wrong about the order, the system settings are only loaded if the user settings don't exist. According to wiki.lxde.org/en/LXSession

Code: Select all

Configuration Files
The config files of LXSession are stored in ~/.config/lxsession/<Profile Name>
If the config files are missing, LXSession loads system-wide config in /etc/xdg/lxsession/<Profile name> instead.
Note: If no -session has been passed on the command line to lxsession, the default profile name is LXDE. 
According to that it looks for a users config first, and if missing it uses the system configuration.
And it says this about the -e and -s arguments:

Code: Select all

--de or -e : Specify the desktop environment name to use for desktop files (such as LXDE, GNOME, or XFCE)
--session or -s : Specify the session name (use for configuration, settings, log files ...). Default to LXDE
Your process results "/usr/bin/lxsession -s LXDE-pi -e LXDE" show it's using the newer LXDE-pi as the session name, and using LXDE as the environment name.
Looking at mine I see "/usr/bin/lxsession -s LXDE -e LXDE" so this RPi is still using LXDE as the session name.

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: sudo nano /etc/xdg/lxsession/LXDE-pi/autostart

Wed Jul 08, 2015 11:27 am

I don't get what the difference is between a "session" and an "environment".

Why have both???

And, for that matter, sometimes they call it a "profile". It sounds like 3 names for the same thing.

It's such a mess.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

Return to “Raspberry Pi OS”