Skip to content

Instantly share code, notes, and snippets.

@fallroot
Created September 19, 2019 04:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fallroot/0a1220f8ac273332eb24a925c7e37117 to your computer and use it in GitHub Desktop.
Save fallroot/0a1220f8ac273332eb24a925c7e37117 to your computer and use it in GitHub Desktop.
Get running apps ordered by most recently used first in macOS
ObjC.import('Cocoa')
const windows = ObjC.deepUnwrap($.CGWindowListCopyWindowInfo($.kCGWindowListOptionOnScreenOnly | $.kCGWindowListExcludeDesktopElements, $.kCGNullWindowID))
Array.from(new Set(windows.map(w => w.kCGWindowOwnerName)))
@vitorgalvao
Copy link

Was getting a TypeError on macOS 12.3.1. Had to add ObjC.castRefToObject:

ObjC.import('Cocoa')

const windows = ObjC.deepUnwrap(ObjC.castRefToObject($.CGWindowListCopyWindowInfo($.kCGWindowListOptionOnScreenOnly | $.kCGWindowListExcludeDesktopElements, $.kCGNullWindowID)))
Array.from(new Set(windows.map(w => w.kCGWindowOwnerName)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment