forked from chilcote/pylab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvisible_apps.py
executable file
·28 lines (22 loc) · 1013 Bytes
/
visible_apps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/python
#ref: https://gist.github.com/pudquick/eebc4d569100c8e3039bf3eae56bee4c
from Foundation import NSBundle
import objc
CoreServices = NSBundle.bundleWithIdentifier_('com.apple.CoreServices')
functions = [
('_LSCopyRunningApplicationArray', '@I'),
('_LSCopyApplicationInformation', '@I@@'),
]
constants = [
('_kLSApplicationTypeKey', '@'),
('_kLSApplicationForegroundTypeKey', '@'),
('_kLSDisplayNameKey', '@')
]
objc.loadBundleFunctions(CoreServices, globals(), functions)
objc.loadBundleVariables(CoreServices, globals(), constants)
apps = _LSCopyRunningApplicationArray(0xfffffffe)
app_infos = [_LSCopyApplicationInformation(0xffffffff, x, None) for x in apps]
visible_app_infos = [x for x in app_infos if x.get(_kLSApplicationTypeKey, None) == _kLSApplicationForegroundTypeKey]
visible_apps = sorted([x.get(_kLSDisplayNameKey) for x in visible_app_infos])
#print visible_app_infos
print visible_apps