How to get/track the active app name from the background app on Mac using SwiftUI?

I am using SwiftUI for MAC App. I am working on the track feature to get the active app on screen from the background. I have implemented the solution below but am unable to get it.

let workspace = NSWorkspace.shared
let applications = workspace.runningApplications        

for application in applications {

    if let url = (application.executableURL?.absoluteString) {

            os_log("%{public}s", log:scribe, type:.debug, url)
        }
    }
}

Or Is it possible to get?

I don't speak Swift, but the frontmostApplication property of NSWorkspace should give you what you want.

How to get/track the active app name from the background app on Mac using SwiftUI?
 
 
Q