[Autostart] Command not working

Hi Lubuntu lovers!

I am using LXQT Session Settings and LXQT Autostart with success in general, but i have an issue with a specific command. I am trying:

wmctrl -s 2 && gimp

But it doesn’t work, but works like normal when i use it on a terminal.
I also tried:

sleep 10 && wmctrl -s 2 && gimp

But also didn’t work.

When using just:

gimp

works like normal. I am using Lubuntu 22.04.2 LTS.

Thanks!

2 Likes

This is a guess, but I think I might know why this is happening.

It looks like you’re trying to pass a shell command to the autostart system. However, the autostart system has a feature for pointing it at a particular application. What that means is that it’s likely that the autostart system is executing the given program directly (i.e., not in a Bash shell or similar), and then passing the arguments you provide to it.

So when you run wmctrl -s 2 && gimp in Bash, it sees this:

wmctrl      -s        2          &&                         gimp
|           |         |          |                          |
application argument1 argument2 (if that succeeds, then do) application

But if you try to execute wmctrl directly, without benefit of the shell to tell it what && means, you get this:

wmctrl      -s        2         &&        gimp
|           |         |         |         |
application argument1 argument2 argument3 argument4

Obviously wmctrl has no clue what to do with && and gimp, so it’s probably erroring out and thus appearing to do absolutely nothing.

The solution I would try is to run bash as the autostart application and then give it the command you want to execute, like this:

bash -c "wmctrl -s 2 && gimp"

The autostart system will then do something like this:

bash        -c        "wmctrl -s 2 && gimp"
|           |         |
application argument1 argument2

That should get your intended command to the shell. Bash will then know what to do with && and should hopefully execute wmctrl -s 2 first and then run gimp.

4 Likes

What @Manux_OS unwittingly was expecting is that any text entered in the ‘Command’-field in the 'Autostart Edit popup-wizard is passed to the shell without any interpreting or loosing functionality.

If it works in the shell, it should work exactly the same way in Autostart as well. Without any magic from his part. Magic, that’s what wizards are for, right?

The same confusion happened to me once, and I am sure we are not the only two persons on this planet. I might elaborate a bit on this one. Make a code change, test it, and prepare a pull request for the LXQt project.

Who knows, it might be accepted for LXQt 1.3.x some day, and end up in Lubuntu at a later date as well.

2 Likes

I have been digging into this a bit more. My (final) idea is that it is best left as is.

A compound bash shell statement (as proposed by @ArrayBolt3) is the best solution. My first idea of (unconditionally or conditionally) wrapping of command text into a -c “construct” might lead to confusion and side effects.

Error handling would be complex. Correct (and timely) execution of all commands in the pipeline of possible complex commands is unpredictable.

In the given example the command wmctlr -s 3 returns immediately (and never fails, or at least does not give an error code which inhibits the next command), so gimp is assured to be executed (on the correct screen, if it exists).

If did not check the Lubuntu manual, but I guess it would be handy to give there an example of this compound usage of Autostart.

3 Likes

I would like to thank both @Fritz and @ArrayBolt3 for your help.
@ArrayBolt3 is right, we need to add bash -c for normal terminal commands to work for LXQT Autostart.

I only had to slight modify this to work. So here are the results!

Interestingly enough, below code worked, it did change to workspace 3, but gimp didn’t load. I also tried sleep with this. sleep and wmctrl worked normal, but gimp didn’t load.

bash -c "wmctrl -s 2 && gimp"

Final solution: So what i did and it actually worked 100% as expected is this:

bash -c "wmctrl -s 2 && exec gimp"

Note: Every time i use the edit button for a command with bash, it adds more and more slashes to the command like this (but works like normal):

bash -c  \\"wmctrl -s 2 && exec gimp\\"

I will need to add more applications to load like this, so while setting up more, will let you know what else i will found out about it :innocent:

1 Like

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.