@MarvinW 
You can send a whole script to the UR with a socket connection to the client at the port 30001 - 30002 - 30003. Your script file must start with a def() end finish with an end to work correctly.  This is an example I have done last year in Python to send a file and execute it:
The script file setzero.script is:
You can find information about this connection on the UR website:
https://www.universal-robots.com/how-tos-and-faqs/how-to/ur-how-tos/remote-control-via-tcpip-16496/
 
         louis_bergeron
                    louis_bergeron
                    
                 MarvinW
                    MarvinW
                    
                 matthewd92
                    matthewd92
                    
                
Hi Everyone,
since the last time it was so helpfull (big thanks to matthewd92!) to ask here a question a have another one.
We have the UR10 and in our applikation the robot have to execute different tasks depending on which state the machine is he has to serve. So, there is a Client which tests something the Robot has to put in. There is a Server connecting this Client to the Robot, sending for the Moment simple commands via the socket Connection. Now we maybe have a bunch of scripts of possible movements of the Robot an there is a objectrecognition function also with a camera. The big question is how to Control everything depending on the different states of the Client. An idea was to have a scriptbib and depending on the state we just send the Robot a whole Script but we did not find out how to do this via the sockets, is this even possible?
Again, thanks a lot and have a good day!