#!/usr/bin/env bash

script="/home/chris/.dotfiles/scripts/kde-list-windows.js"

num=$(dbus-send --print-reply --dest=org.kde.KWin \
    /Scripting org.kde.kwin.Scripting.loadScript \
    string:"$script" | awk 'END {print $2}' )

echo $num

wins=$(dbus-send --print-reply --dest=org.kde.KWin /$num \
    org.kde.kwin.Script.run | sed 's/p/p/')

echo $wins
# I'm not sure if some delay is in order here to let your script complete?
sleep 1
dbus-send --print-reply --dest=org.kde.KWin /$num \
    org.kde.kwin.Script.stop
