get previous active application

Hi there, i need too access the previuos active App to send Keystrokes to it, how do i accomplish this, e,g, Safari has Focus, i activate Mail, so Mail is now frontmost, how to find the App Safari which is not frontmost anymore?

thx in afance

The mac has a keyboard command (cmd-tab) to switch between applications. You can use this to go to the previously frontmost application so the following would work.

NOTE: you have to run this applescript so that it does not become frontmost when running it otherwise when run the applescript will go back and the wrong application (not the one you expect) will come frontmost. The easiest way to do that is to run this script from the Scripts Menu.

tell application "System Events" to keystroke tab using command down

Yes this worked very good, i just used your command to jump back, send the key strokes and use your command again to jump back again to the desired FrontMost Application, but sadly the script did not work as i expected or hoped it will do ^^

Nevermind, however, i have learned something ^^

thx again

I have found another way to do this that works Here!