Last active
February 2, 2016 17:02
-
-
Save arlm/bd2a2f4028cc2ebbfd0e to your computer and use it in GitHub Desktop.
Mac OS X scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# From http://blog.loudhush.ro/2014/04/what-process-owns-certain-window-mac-os.html | |
# Show all windows that were moved on the last 5 seconds | |
import time | |
from Quartz import CGWindowListCopyWindowInfo, kCGWindowListExcludeDesktopElements, kCGNullWindowID | |
from Foundation import NSSet, NSMutableSet | |
wl1 = CGWindowListCopyWindowInfo(kCGWindowListExcludeDesktopElements, kCGNullWindowID) | |
print 'Move target window' | |
time.sleep(5) | |
wl2 = CGWindowListCopyWindowInfo(kCGWindowListExcludeDesktopElements, kCGNullWindowID) | |
w = NSMutableSet.setWithArray_(wl1) | |
w.minusSet_(NSSet.setWithArray_(wl2)) | |
print '\nList of windows that moved:' | |
print w | |
print '\n' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Extracted from https://github.com/sjitech/mac_list_windows_pids/blob/master/lswin.py | |
# List all windows and PIDs showing their title | |
import Quartz | |
#wl = Quartz.CGWindowListCopyWindowInfo( Quartz.kCGWindowListOptionOnScreenOnly | Quartz.kCGWindowListExcludeDesktopElements, Quartz.kCGNullWindowID) | |
wl = Quartz.CGWindowListCopyWindowInfo( Quartz.kCGWindowListOptionAll, Quartz.kCGNullWindowID) | |
wl = sorted(wl, key=lambda k: k.valueForKey_('kCGWindowOwnerPID')) | |
#print wl | |
print 'PID'.rjust(7) + ' ' + 'WinID'.rjust(5) + ' ' + 'x,y,w,h'.ljust(21) + ' ' + '\t[Title] SubTitle' | |
print '-'.rjust(7,'-') + ' ' + '-'.rjust(5,'-') + ' ' + '-'.ljust(21,'-') + ' ' + '\t-------------------------------------------' | |
for v in wl: | |
print ( \ | |
str(v.valueForKey_('kCGWindowOwnerPID') or '?').rjust(7) + \ | |
' ' + str(v.valueForKey_('kCGWindowNumber') or '?').rjust(5) + \ | |
' {' + ('' if v.valueForKey_('kCGWindowBounds') is None else \ | |
( \ | |
str(int(v.valueForKey_('kCGWindowBounds').valueForKey_('X'))) + ',' + \ | |
str(int(v.valueForKey_('kCGWindowBounds').valueForKey_('Y'))) + ',' + \ | |
str(int(v.valueForKey_('kCGWindowBounds').valueForKey_('Width'))) + ',' + \ | |
str(int(v.valueForKey_('kCGWindowBounds').valueForKey_('Height'))) \ | |
) \ | |
).ljust(21) + \ | |
'}' + \ | |
'\t[' + ((v.valueForKey_('kCGWindowOwnerName') or '') + ']') + \ | |
('' if v.valueForKey_('kCGWindowName') is None else (' ' + v.valueForKey_('kCGWindowName') or '')) \ | |
).encode('utf8') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment