Why not use ```osascript -e 'application (path to frontmost application as text)'```?