kdotool uses KWin’s scripting API to control windows. In each invocation, it generates a KWin script on-the-fly, loads it into KWin, runs it, and then deletes it, using KWin’s DBus interface.

This program should work with both KDE 5 and the upcoming KDE 6.