Getting the name of the last frontmost application

When hopping between applications, Command-Tab will always return you to the application running just prior to the one now frontmost, i.e. frontmost - 1. If I want to know the name of that application (the one before the frontmost one) how do I get it in a script?

Quick question: What are you trying to accomplish?

I’m asking this for two reasons: first because I don’t know how to do it, but second in response to this post where the poster wants to write a script that will interact with whatever the previously active application was (without knowing the name of the application).

There is a solution posted here by Jacques