Hey, well done! For these kinds of tasks, myself I regularly use the venerable Expect [0].
Undroidwish [0] is a Tcl/Tk binary that apparently has experimental support for Wayland (through SDL). It's a spin-off from Androwish [1], but more for desktop/embedded systems.
You might have something there, as Expect is supported for Androwish already.