Last active
May 2, 2020 10:47
-
-
Save aessam/8c6bb57502be580fc940bd0ae8760a0a to your computer and use it in GitHub Desktop.
Take a screenshot for a window, query by window title (windowShot.py 'Mail') output to tmp directory.
This file contains 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
import os | |
from sys import argv | |
from Quartz import CGWindowListCopyWindowInfo, kCGWindowListExcludeDesktopElements, kCGNullWindowID,kCGWindowListOptionOnScreenOnly | |
windowList = CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements, kCGNullWindowID) | |
systemWindows = ['SystemUIServer', 'Window Server', 'Spotlight'] | |
searchname = argv[1].lower() | |
for i in windowList: | |
if searchname in i['kCGWindowOwnerName'].lower() and i['kCGWindowOwnerName'] not in systemWindows: | |
print(i['kCGWindowNumber'], i['kCGWindowOwnerName']) | |
os.system('screencapture -l{0} "tmp/{0}{1}.png"'.format(i['kCGWindowNumber'], i['kCGWindowOwnerName'])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment