how to write automation scripts