Other Qtile - unable to create keybindings that run a sh command

I want to add custom key bindings in the qtile config (~/.config/qtile/config.py) to run arbitrary sh commands.
Normally to do this one must access the prompt widget (mod+r), and then manually type the command.
Instead I want to set a custom keybinding to essentially access the prompt widget, enter an arbitrary sh command, and execute that command as if I had pressed the return key. Of course it does not have to be so complicated. It could be a simple keybinding to call on "subprocess.run" to execute the command immediately and directly.

The specific commands I have been trying to keybind are
mixer vol -5, bound to mod+-
mixer vol +5, bound to mod+=

I have tried adding each of these keys list. Here are a few examples of what I have tried,
Code:
Key([mod], "-", lazy.function(Volume_Down)) # Volume_Down(): subrocess.run(["mixer", "vol", "-5"])
Key([mod], "-", lazy.spawn("mixer vol -5"))
Key([mod], "-", lazy.spawncmd(command=["mixer", "vol", "-5"], shell=True))
Key([mod], "-", lazy.spawncmd(command="mixer vol -5", shell=True))
Key([mod], "-", lazy.cmd_spawncmd(command=["mixer", "vol", "-5"], shell=True))
Along with the variations to raise the volume. The above list is not comprehensive but it gets the gist.

Extra info:
-I am using python 3.9.13
-The 'mod' key refers to the 'super' key (windows key on most keyboards)
-I am fine with using another key combination like alt+[ or whatever
-Qtile can do volume control via audio/pamixer I think, and while that might solve my problem of audio control, it does not solve the bigger issue of the inability to keybind terminal commands
-If x11/xorg can do the same thing, i.e. handle keybindings to terminal commands, that is fine too but I am unfamiliar with doing such a thing on xorg

Thank you in advance for any help!
Apologies in advance for slow replies.
 
Hi i had a simular issue, i solved it with your first idea:

Python:
def Volume_Down(qtile):
    subprocess.run(["mixer vol -5"], shell=True)


Key([mod], "-", lazy.function(Volume_Down))

at first it wasnt clear why, but the method you use in a lazy.function requires a to have at positional argument at index 0 for qtile.

Doc:
lazy.function(func, *args, **kwargs) -> Calls func(qtile, *args, **kwargs). NB. the qtile object is automatically passed as the first argument.
 
Back
Top