I suspect that what ever you are doing, there is an easier way. But automating what you are asking for is surely not it. What is it you are trying to do?