#[SOLVED] bash script help

24 messages · Page 1 of 1 (latest)

honest pelican
#
[silvia@desktop] [22:25:48] [554] [~]
 >> niri msg --json event-stream | jq -r 'select(.WorkspaceActivated) | .WorkspaceActivated.id'
47
46
^C
[silvia@desktop] [22:27:49] [556] [~]
 >> niri msg --json workspaces | jq -r '.[] | select(.id == 46) | .name'
Discord

heres all of the previous attempts to crack this

#

@dark hare

dark hare
# honest pelican <@1121362940403126302>

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
honest pelican
#

still nothing...

dark hare
# honest pelican 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
honest pelican
dark hare
# honest pelican stil nothing... ``` [silvia@desktop] [23:42:31] [567] [~] >> ./get-niri-worlspa...

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
dark hare
honest pelican
#

lol ok

dark hare
# honest pelican `niri msg -j workspaces | jq`

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
solid vergeBOT
#

alpha_b_9 received a thank you cookie!

honest pelican
#

u deserve all the cookies

#

all of them

#

gives u a big ol smooch

dark hare
honest pelican
#

[SOLVED] bash script help

honest pelican
dark hare