Have you looked into Keyboard Maestro?  I use it all the time,  I believe you can accomplish with what you want using Keyboard Maestro.

For example:  You can have it check for a typed in string "good" and return morning or afternoon based on the time of day.

![enter image description here][1]

  [1]: http://i.stack.imgur.com/Y3qPn.png

With Keyboard Maestro you can execute AppleScript or Shell scripts.  Keyboard is pretty powerful.   Your macros can then be global or specific to an application.