automation based on actions

I’m looking for code that will automate the block when something happens. This is much broader than just hotkeys in my earlier post, so that’s why I’m putting a new one.
for instance, when you open an application the script runs and then opens another application.
Or, you click a menu bar icon and your script runs
Or, you select a folder on the desktop and the script runs
I can’t figure out how to do anything near that. If anyone knows, I would be deeply obliged.
Thanks so much.