How to execute more than one command in a single lazy call ?

124 views
Skip to first unread message

Piyush Chaudhary

unread,
Jul 16, 2024, 2:19:02 PM7/16/24
to qtile-dev
I am trying to get notifications when i increase my volume, so i created a bash script and binded it together to the same key which i use to increase my volume but when i restart qtile and press the key, nothing happens. The notification doesn't show up and the volume does not increase or decrease.

config.py:
Key([], "XF86AudioMute", lazy.spawn("pactl set-sink-mute 0 toggle && /home/Odd/.config/qtile/dunst_volume_monitor.
Key([], "XF86AudioLowerVolume", lazy.spawn("pactl set-sink-volume 0 -10% && /home/Odd/.config/qtile/dunst_volume_monitor.
Key([], "XF86AudioRaiseVolume", lazy.spawn("pactl set-sink-volume 0 +10% && /home/Odd/.config/qtile/dunst_volume_monitor.sh")),

I tried running the script manually through the command line to see if there was any issue, and it worked gracefully.

Sorry if i am making any dumb mistakes here, i am new to linux and qtile.

Kai Stian Olstad

unread,
Jul 16, 2024, 2:35:21 PM7/16/24
to qtil...@googlegroups.com
spawn is not a shell, so you can't use && in there.
But you can use a shell like this

Key([], "XF86AudioMute", lazy.spawn("bash", "-c", "pactl set-sink-mute 0 toggle && /home/Odd/.config/qtile/dunst_volume_monitor.sh")),

--
Kai Stian

Tycho Andersen

unread,
Jul 16, 2024, 3:24:59 PM7/16/24
to 'Kai Stian Olstad' via qtile-dev
There is `shell=True` though, which you can use to spawn a command
inside a shell.

Tycho
Message has been deleted

Piyush Chaudhary

unread,
Jul 16, 2024, 5:01:18 PM7/16/24
to qtile-dev
config.py:

Key([], "XF86AudioMute", lazy.spawn("bash", "-c", "pactl set-sink-mute 0 toggle && /home/Odd/.config/qtile/dunst_volume_monitor.sh")
Key([], "XF86AudioLowerVolume", lazy.spawn("bash", "-c", "pactl set-sink-volume 0 -10% && /home/Odd/.config/qtile/dunst_volume_monitor.sh"),
Key([], "XF86AudioRaiseVolume", lazy.spawn("bash", "-c", "pactl set-sink-volume 0 +10% && /home/Odd/.config/qtile/dunst_volume_monitor"),

i did as told above but noting worked, additionally qtile broke down in a weird way like not opening terminal, not switching workspaces, not opening applications:

i went to check out the log and this is the latest log:
2024-07-16 22:28:49,148 ERROR libqtile core.py:_xpoll():L359 Got an exception in poll loop
Traceback (most recent call last):
  File "/usr/lib/python3.12/site-packages/libqtile/backend/x11/core.py", line 334, in _xpoll
    self.handle_event(event)
  File "/usr/lib/python3.12/site-packages/libqtile/backend/x11/core.py", line 301, in handle_event
    ret = target(event)
          ^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/libqtile/backend/x11/window.py", line 2210, in handle_PropertyNotify
    self.update_hints()
  File "/usr/lib/python3.12/site-packages/libqtile/backend/x11/window.py", line 618, in update_hints
    h = self.window.get_wm_hints()
        ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/libqtile/backend/x11/window.py", line 184, in get_wm_hints
    wm_hints = self.get_property("WM_HINTS", xcffib.xproto.GetPropertyType.Any)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/libqtile/backend/x11/window.py", line 382, in get_property
    ).reply()
      ^^^^^^^
  File "/usr/lib/python3.12/site-packages/xcffib/__init__.py", line 330, in reply
    data = self.conn.wait_for_reply(self.sequence)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/xcffib/__init__.py", line 579, in wrapper
    return f(*args)
           ^^^^^^^^
  File "/usr/lib/python3.12/site-packages/xcffib/__init__.py", line 673, in wait_for_reply
    raise XcffibException("Bad sequence number %d" % sequence)
xcffib.XcffibException: Bad sequence number 43800

Kai Stian Olstad

unread,
Jul 16, 2024, 5:39:58 PM7/16/24
to qtil...@googlegroups.com
On Tue, Jul 16, 2024 at 10:01:17AM -0700, Piyush Chaudhary wrote:
>config.py:
>
>Key([], "XF86AudioMute", lazy.spawn("bash", "-c", "pactl set-sink-mute 0
>toggle && /home/Odd/.config/qtile/dunst_volume_monitor.sh")
>Key([], "XF86AudioLowerVolume", lazy.spawn("bash", "-c", "pactl
>set-sink-volume 0 -10% && /home/Odd/.config/qtile/dunst_volume_monitor.sh"),
>Key([], "XF86AudioRaiseVolume", lazy.spawn("bash", "-c", "pactl
>set-sink-volume 0 +10% && /home/Odd/.config/qtile/dunst_volume_monitor"),
>
>i did as told above but noting worked, additionally qtile broke down in a
>weird way like not opening terminal, not switching workspaces, not opening
>applications:

My solution doesn't work, I have seen this someplace so I thought it would
work.

But as Tycho said, it has shell=True so you can do this.
Key([], "XF86AudioMute", lazy.spawn("pactl set-sink-mute 0 toggle && /home/Odd/.config/qtile/dunst_volume_monitor.sh", shell=True),


>On Tuesday, July 16, 2024 at 8:54:59 PM UTC+5:30 Tycho Andersen wrote:
>
>> toggle && /home/Odd/.config/qtile/dunst_volume_monitor.sh")),
>>
>> There is `shell=True` though, which you can use to spawn a command
>> inside a shell.

Aha, thanks. It's not in the documentation unfortunately.
But found a PR, https://github.com/qtile/qtile/pull/4709, that it also support
env :-)

--
Kai Stian

Piyush Chaudhary

unread,
Jul 16, 2024, 5:43:35 PM7/16/24
to qtile-dev
what am i supposed to do to fix it ?

Tycho Andersen

unread,
Jul 16, 2024, 5:52:21 PM7/16/24
to 'Kai Stian Olstad' via qtile-dev
I see it in the docs: https://docs.qtile.org/en/stable/manual/commands/api/root.html#libqtile.core.manager.Qtile.spawn

but maybe we are generating them in multiple places? where did you
look?

Tycho
Message has been deleted

Piyush Chaudhary

unread,
Jul 16, 2024, 6:01:18 PM7/16/24
to qtile-dev
where did i look for what ? i am sorry i am not able to keep up with this conversation effectively, i am very new to forums and CS.

Kai Stian Olstad

unread,
Jul 16, 2024, 6:13:55 PM7/16/24
to qtil...@googlegroups.com
I search for lazy.spawn and the first link was this
https://docs.qtile.org/en/stable/manual/config/lazy.html

And your link did not show up because I searched for lazy.spawn and not spawn.
But searching for any spawn it's the first link in the list.

--
Kai Stian

Piyush Chaudhary

unread,
Jul 16, 2024, 6:16:56 PM7/16/24
to qtile-dev
Ok its working now i used shell = True and it worked:
Key([], "XF86AudioMute", lazy.spawn("pactl set-sink-mute 0 toggle && /home/Odd/.config/qtile/dunst_volume_monitor.sh", shell=True)),

It was not working when i used this:
Key([], "XF86AudioMute", lazy.spawn("bash", "-c", "pactl set-sink-mute 0 toggle && /home/Odd/.config/qtile/dunst_volume_monitor.sh")),

Can you explain why ?

Kai Stian Olstad

unread,
Jul 16, 2024, 6:34:01 PM7/16/24
to qtil...@googlegroups.com
On Tue, Jul 16, 2024 at 11:16:55AM -0700, Piyush Chaudhary wrote:
>Ok its working now i used shell = True and it worked:
>Key([], "XF86AudioMute", lazy.spawn("pactl set-sink-mute 0 toggle &&
>/home/Odd/.config/qtile/dunst_volume_monitor.sh", shell=True)),
>
>It was not working when i used this:
>Key([], "XF86AudioMute", lazy.spawn("bash", "-c", "pactl set-sink-mute 0
>toggle && /home/Odd/.config/qtile/dunst_volume_monitor.sh")),
>
>Can you explain why ?

Because I forgot to include [], so this line would also work.

Key([], "XF86AudioMute", lazy.spawn(["bash", "-c", "pactl set-sink-mute 0 toggle && /home/Odd/.config/qtile/dunst_volume_monitor.sh"])),


--
Kai Stian

Piyush Chaudhary

unread,
Jul 16, 2024, 7:00:35 PM7/16/24
to qtile-dev
what do these parameters indicate here like "bash", "-c" ?
Key([], "XF86AudioMute", lazy.spawn(["bash", "-c", "pactl set-sink-mute 0 toggle && /home/Odd/.config/qtile/dunst_volume_monitor.sh"])),

and how the above function call is different from the this one:
Key([], "XF86AudioMute", lazy.spawn("pactl set-sink-mute 0 toggle && /home/Odd/.config/qtile/dunst_volume_monitor.sh", shell=True)),

is the spawn function overloaded.

Kai Stian Olstad

unread,
Jul 16, 2024, 7:48:33 PM7/16/24
to qtil...@googlegroups.com
On Tue, Jul 16, 2024 at 12:00:35PM -0700, Piyush Chaudhary wrote:
>what do these parameters indicate here like "bash", "-c" ?
>Key([], "XF86AudioMute", lazy.spawn(["bash", "-c", "pactl set-sink-mute 0
>toggle && /home/Odd/.config/qtile/dunst_volume_monitor.sh"])),

bash is a shell and -c is a option to bash to run commands inside the bash
shell.
I recommend reading "man bash" and check out the option "-c" if you want to know
more.


>and how the above function call is different from the this one:
>Key([], "XF86AudioMute", lazy.spawn("pactl set-sink-mute 0 toggle &&
>/home/Odd/.config/qtile/dunst_volume_monitor.sh", shell=True)),

When you use shell=True Qtile add the "bash -c" for you.
(to be technically correct "shell=True" uses "sh -c" and not "bash -c", but
for you in this case the result is the same)


>is the spawn function overloaded.

I wouldn't say that, but Linux have many ways to do the same thing.
So which of them you use is up to you, both work and in the end they do the
same thing.

--
Kai Stian

Piyush Chaudhary

unread,
Jul 16, 2024, 7:56:31 PM7/16/24
to qtile-dev
Got it. Thanks Everyone for all your help. 

Piyush Chaudhary

unread,
Jul 16, 2024, 7:57:39 PM7/16/24
to qtile-dev
Do I have to close this post or mark it as solved as we have to so in the arch Linux forum ?

Tycho Andersen

unread,
Jul 16, 2024, 7:57:43 PM7/16/24
to 'Kai Stian Olstad' via qtile-dev
Yeah, I think the lazy section should probably just link to the docs
that are generated directly from the docstrings, vs. trying to
reproduce it poorly. Can you file a bug?

Tycho

Piyush Chaudhary

unread,
Jul 16, 2024, 8:03:22 PM7/16/24
to qtile-dev
Do I have to file it here ?

Kai Stian Olstad

unread,
Jul 16, 2024, 8:41:20 PM7/16/24
to qtil...@googlegroups.com
I tried https://github.com/qtile/qtile/issues/4926 hopefully it's understandable.

--
Kai Stian

Kai Stian Olstad

unread,
Jul 16, 2024, 8:43:47 PM7/16/24
to qtil...@googlegroups.com
On Tue, Jul 16, 2024 at 01:03:22PM -0700, Piyush Chaudhary wrote:
>Do I have to file it here ?
>https://github.com/qtile/qtile/

I think the question was direct at me so I created one here
https://github.com/qtile/qtile/issues/4926

--
Kai Stian

Kai Stian Olstad

unread,
Jul 16, 2024, 8:49:36 PM7/16/24
to qtil...@googlegroups.com
On Tue, Jul 16, 2024 at 12:57:39PM -0700, Piyush Chaudhary wrote:
>Do I have to close this post or mark it as solved as we have to so in the
>arch Linux forum ?

No, a mailinglist like this one have no such concept.
The only think we ask is that people post what work for them in the end so it
help next person finding this thread.
But you have done that so everything is good.

--
Kai Stian
Reply all
Reply to author
Forward
0 new messages