List The Foreground Apps Running On A Mac With JavaScript

#!/usr/bin/env osascript -l JavaScript

const sysEvents = Application("System Events")
const allProcesses = sysEvents.processes
const foregroundProcesses = allProcesses.whose({"backgroundOnly": {'=': false }})

for (let pIndex = 0; pIndex < foregroundProcesses.length; pIndex ++ ) {
  console.log(
    ``${pIndex} - `` +
    ``${foregroundProcesses[pIndex].name()} - `` +
    `${foregroundProcesses[pIndex].displayedName()}`
  )
}
TODO: Show Results Output

Notes

~ fin ~