Window-specific document script?

I made this post the other day: [demo] Attach metadata GUI to taskpaper app windows

it’s evolved since then (with help of some custom written swift software) so down to when I drag a taskpaper window around the gui attaches to the window in real time. it works for multiple windows of different files, but the problem is this system isn’t working for multiple windows of same file (but different projects) as they resolve to the same document