So this is something that has been explored before, currently the only way to do it is use a python program, daemon, and urcap to create additional URscript functions to call within a program, check links below:
If someone from UR gets hold of this thread is this something you guys can integrate into next revision of Polyscope this topic has been brought up a few times now.