I don't think there is a good way to do that. I wouldn't recommend editing toolbar xml in a script as if you get it wrong you could corrupt your toolbar. But it is one option if you really want to go down that path. You'd probably need to close and reopen the toolbar after the file was modified, and making a backup of the old toolbar would make sense.
The script could create a .dcf file which you then drag to your toolbar, which would be safer.