You can probably do this, but be careful, Blizzard has some pretty sophisticated methods for detecting any kind of cheats including client-side scripting. It's not allowed in the TOS and they could certainly terminate your account immediately if you get caught. You might be better off using an in-game LUA script, although I don't know the specifics of what's allowed.