PyObjC Social Framework

12.1 · active · verified Tue Apr 14

PyObjC is a bridge between Python and Objective-C, enabling Python developers to write full-featured Cocoa applications and interact with macOS system frameworks. The `pyobjc-framework-social` package provides Python wrappers for Apple's Social.framework, allowing programmatic access to social media services integrated into macOS, such as sharing content. The library is currently at version 12.1 and typically releases updates in alignment with major macOS SDK changes and Python version support.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to import and use basic functionality from the `Social` framework to check the availability of social media services (Twitter and Facebook) on macOS. It highlights the direct access to Objective-C classes and their static methods provided by PyObjC. Note that interacting with the UI for composing a post (e.g., displaying `SLComposeViewController`) would require a running `NSApplication` event loop, which is a more involved setup not covered in this minimal example.

import objc
from Social import SLComposeViewController, SLServiceTypeTwitter, SLServiceTypeFacebook

def check_social_services():
    """
    Checks if Twitter and Facebook social services are available on macOS.
    Note: This example demonstrates basic availability checks without
    requiring a full NSApplication event loop for UI presentation.
    """
    # Explicitly load the Social framework if not already done by imports.
    # This is often implicit but good for clarity in specific cases.
    objc.loadBundle("Social", globals(), bundle_path=objc.pathForFramework("/System/Library/Frameworks/Social.framework"))

    twitter_available = SLComposeViewController.isAvailableForServiceType_(SLServiceTypeTwitter)
    facebook_available = SLComposeViewController.isAvailableForServiceType_(SLServiceTypeFacebook)

    print(f"Twitter service available: {twitter_available}")
    print(f"Facebook service available: {facebook_available}")

if __name__ == "__main__":
    check_social_services()

view raw JSON →