display-switch icon indicating copy to clipboard operation
display-switch copied to clipboard

Support multiple command executions with `on_usb_<event>_execute`

Open bil0u opened this issue 1 year ago • 1 comments

Hi there, thanks for your work on this project.

I'm using a custom version of m1ddc to send switching input commands to my displays when my USB switch is disconnected, and the binary needs to be called for each display.

It would be great to support execution of multiple commands when usb events are fired.

An easy implementation (tested) would be to split the command string on the ; delimiter, and call each command successively.


https://github.com/haimgel/display-switch/blob/a5b76e0d04a84051b7fc6dac212143bce5760b41/src/display_control.rs#L180-L181

would be replaced by

for subcommand in execute_command.split(";") {
    let subcommand = subcommand.trim();
    if !subcommand.is_empty() {
        try_run_command(subcommand).unwrap_or_else(|err| error!("Error executing external command '{}': {}", subcommand, err));
    }
}

What do you think ?

bil0u avatar Nov 20 '23 00:11 bil0u

I am also using m1ddc to swap multiple monitors at the same time. You can chain commands in this fashion without needing anything additional if you wish:

# Example
on_usb_connect_execute = "sh -c \"m1ddc display 1 set input 1 && m1ddc display 2 set input 1\""

Unsure if escaping the inner quotations is needed here, but this seems to work for me.

zerosym avatar Jan 20 '24 08:01 zerosym