When you write a script, you write it to your hearts content. So yes, you could write it to automatically connect to Tor. However, Tor is a network of layered encryption called onion routing designed around privacy, not efficiency. If you use Tor, you accept the experience of using Tor.