tell application "System Events"

tell application "System Events" tell (first application process whose frontmost is true) -- the "it" is this script set my_app to name of it set visible of it to false delay 0.2 -- now, the "it" becomes the previous frontmost app set theActiveApp to name of it end tell end tell tell application "System Events" set visible of application process my_app to true tell application "Music" to activate set visible of application process my_app to true end tell display dialog my_app