Looks like this thread, particularly the post from @Chauncey, shows a Keyboard Maestro-based approach to doing what you'd like.
There's also a related thread perhaps worth looking over for ideas:
For more information, see the wiki Searching the Forum for Answers section.