#[SOLVED] bash script help
24 messages · Page 1 of 1 (latest)
Try
#!/usr/bin/env bash
declare -A ws_names
while read -r ws; do
id=$(echo "$ws" | jq '.id')
name=$(echo "$ws" | jq -r '.name')
ws_names["$id"]="$name"
done < <(niri msg --json workspaces | jq -c '.[]')
last=""
niri msg --json event-stream \
| jq -c 'select(.WorkspaceActivated)' \
| while read -r event; do
id=$(echo "$event" | jq '.WorkspaceActivated.id')
name="${ws_names[$id]}"
if [[ "$name" != "$last" ]]; then
echo "$name"
last="$name"
fi
done
still nothing...
#!/usr/bin/env bash
last_name=""
niri msg --json event-stream \
| jq -r 'select(.WorkspaceActivated) | .WorkspaceActivated.id' \
| while read -r ws_id; do
sleep 0.05
ws_name=$(niri msg --json workspaces \
| jq -r --argjson id "$ws_id" '.[] | select(.id == $id) | .name')
if [[ "$ws_name" != "$last_name" ]]; then
echo "$ws_name"
last_name="$ws_name"
fi
done
stil nothing...
[silvia@desktop] [23:42:31] [567] [~]
>> ./get-niri-worlspace.sh
^C
Try this one
#!/usr/bin/env bash
declare -A ws_names
ws_names[43]="Browser"
ws_names[44]="Code"
ws_names[45]="Terminal"
ws_names[46]="Files"
last_name=""
niri msg --json event-stream \
| jq -r 'select(.WorkspaceActivated) | .WorkspaceActivated.id' \
| while read -r ws_id; do
ws_name="${ws_names[$ws_id]:-$ws_id}"
if [[ "$ws_name" != "$last_name" ]]; then
echo "$ws_name"
last_name="$ws_name"
fi
done
:(
Share all the related Niri stuff, I’m going to science the heck out of this.
Run
#!/usr/bin/env bash
declare -A ws_names
last_name=""
niri msg --json event-stream | while read -r line; do
event=$(echo "$line" | jq -c '.')
if echo "$event" | jq 'has("WorkspacesChanged")' | grep -q true; then
for ws in $(echo "$event" | jq -c '.WorkspacesChanged.workspaces[]'); do
id=$(echo "$ws" | jq -r '.id')
name=$(echo "$ws" | jq -r '.name // empty')
[[ -n "$name" ]] && ws_names[$id]="$name"
done
fi
if echo "$event" | jq 'has("WorkspaceActivated")' | grep -q true; then
id=$(echo "$event" | jq -r '.WorkspaceActivated.id')
name="${ws_names[$id]:-$id}"
if [[ "$name" != "$last_name" ]]; then
echo "$name"
last_name="$name"
fi
fi
done
IT WORKS
THANK YOU
alpha_b_9 received a thank you cookie!
Awesome.
[SOLVED] bash script help
ur amazing
Takes one to know one!