Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

List The Foreground Apps Running On A Mac With JavaScript

Code

#!/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()}`
  )
}

Results

0 - Finder - Finder
1 - Google Chrome - Google Chrome
2 - sublime_text - Sublime Text
3 - GitHub Desktop - GitHub Desktop
4 - Vivaldi - Vivaldi
5 - Keychain Access - Keychain Access
6 - Soulver 3 - Soulver 3
7 - Stickies - Stickies
8 - iTerm2 - iTerm2
9 - Loopback - Loopback
10 - Activity Monitor - Activity Monitor
11 - Terminal - Terminal
12 - Electron - Code
13 - Spotify - Spotify
14 - TextEdit - TextEdit
15 - Adobe Photoshop 2023 - Adobe Photoshop 2023
16 - Safari - Safari
17 - firefox - Firefox