Skip to content

Instantly share code, notes, and snippets.

@aessam
Last active May 2, 2020 10:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aessam/8c6bb57502be580fc940bd0ae8760a0a to your computer and use it in GitHub Desktop.
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.
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