`swaymsg <criteria> nop` returns a non-zero return value on failure,
allowing conditional decisions for use in scripting.
```
$ swaymsg '[app_id="foot"]' nop ; echo $?
0
$ swaymsg '[app_id="foot"]' nop ; echo $?
Error: No matching node.
2
$
```
I think it would be useful if the swayr nop command could do this as well.
I imagine it would make scripting easier by allowing simple use of
OR, NOT, and nesting of conditions that cannot be specified with `swaymsg`.
"Takahashi, Naoki" <tkna91@gmail.com> writes:
> `swaymsg <criteria> nop` returns a non-zero return value on failure,> allowing conditional decisions for use in scripting.>> ```> $ swaymsg '[app_id="foot"]' nop ; echo $?> 0> $ swaymsg '[app_id="foot"]' nop ; echo $?> Error: No matching node.> 2> $> ```
Interesting, I didn't know that!
> I think it would be useful if the swayr nop command could do this as> well.
Yes, absolutely. I'll make it so when I find some spare time. :-)
Bye,
Tassilo
Sorry, my example was a bit wrong. It is as follows.
```
$ swaymsg '[app_id="foot"]' nop ; echo $?
0
$ swaymsg '[app_id="foott"]' nop ; echo $?
Error: No matching node.
2
$
```
Tassilo Horn <tsdh@gnu.org> writes:
>> I think it would be useful if the swayr nop command could do this as>> well.>> Yes, absolutely. I'll make it so when I find some spare time. :-)
It's done! However, I didn't extend the nop command but the (until now
undocumented) get-windows-as-json command. See the last command in
https://sr.ht/~tsdh/swayr/#miscellaneous-commands.
It's only in the main branch so far but I'll release 0.26.0 shortly. It
would be great if you could do some testing.
Bye,
Tassilo
Thanks. As far as I'm briefly testing it now, it doesn't seem to have any glitches.
I think it would be easy to understand if you could do the same thing with 'swayr nop <CRITERIA>' as below, but what do you think?
```
$ swayr get-windows-as-json --error-if-no-match --matching '[app_name="foot"]' >/dev/null ; echo $?
0
$ swayr get-windows-as-json --error-if-no-match --matching '[app_name="foott"]' >/dev/null ; echo $?
Error: "No matching windows"
1
$
```
"Takahashi, Naoki" <tkna91@gmail.com> writes:
> Thanks. As far as I'm briefly testing it now, it doesn't seem to have> any glitches.
Thanks!
> I think it would be easy to understand if you could do the same thing> with 'swayr nop <CRITERIA>' as below, but what do you think?
You mean, make "swayr nop <CRITERIA>" an alternative to "swayr
get-windows-as-json -m <CRITERIA> -e" just without the JSON output? If
that's the question, the answer is a No because the nop command already
has a specific meaning in swayr: it ends the current next/prev sequence.
It it were used by shell scripts, this effect could lead to strange
effects. It would basically be an auto-nop triggered at possibly random
times by scripts.
Oh, now that I've written the above it occurs to me that
get-windows-as-json will do the same! So I'll add an exception that
this command, which is just a tool for scripting, doesn't end the
current next/prev sequence. :-)
Bye,
Tassilo
Understood. It seems that the original purpose was different,
so it cannot be replaced with another function.
Thank you for the implementation.
I'm pleased it has become more convenient.