PyObjC ScreenCaptureKit Framework Bindings

12.1 · active · verified Tue Apr 14

PyObjC-framework-ScreenCaptureKit provides Python bindings for Apple's ScreenCaptureKit framework on macOS. It enables Python applications to interact with macOS screen recording functionalities. This library is part of the larger PyObjC project, receiving updates in sync with macOS SDK changes and Python versions. The current version is 12.1, released with a focus on macOS SDK updates and Python 3.10+ compatibility.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to list available screen capture content (applications, displays, windows) using `SCShareableContent`. Note that running this code requires 'Screen Recording' permissions to be granted to your Python environment in macOS System Settings > Privacy & Security. Asynchronous operations in `ScreenCaptureKit` require the `NSRunLoop` to be active for completion handlers to execute.

import ScreenCaptureKit
from Foundation import NSLog, NSDate
import objc

# Define a completion handler for the asynchronous call
def completion_handler(content, error):
    if error:
        NSLog("Error getting shareable content: %@", error)
    elif content:
        NSLog("Successfully retrieved shareable content:")
        NSLog("Applications: %s", content.applications())
        NSLog("Displays: %s", content.displays())
        NSLog("Windows: %s", content.windows())
    else:
        NSLog("No content or error.")

# Asynchronously get available screen capture content
# Note: This requires 'Screen Recording' permission in macOS System Settings.
ScreenCaptureKit.SCShareableContent.getShareableContentWithCompletionHandler_(completion_handler)

# Keep the runloop active briefly for the completion handler to execute.
# In a full Cocoa application, this would be handled by the app's main runloop.
objc.currentEventLoop().runUntilDate_(NSDate.dateWithTimeIntervalSinceNow_(2))

view raw JSON →