There are two tools very useful for this:
- Automator
- MacroRecorder
Automator
This is very powerful, but quite difficult to use especially at the beginning.
It is install by default on Mac.
You can find this tutorial about how to record a workflow, and this other about how to play with variables.
MacroRecorder
Easier to use in comparison to Automator, but less powerful.
This tool is available for Mac and Windows
You need to download and install it from here.