PyObjC LaunchServices Framework

12.1 · active · verified Tue Apr 14

PyObjC-framework-LaunchServices provides Python bindings for Apple's LaunchServices framework on macOS. It allows Python applications to interact with macOS features like launching applications, opening files, and querying file type information. Part of the larger PyObjC project, it is currently at version 12.1 and typically releases alongside new macOS SDK versions and Python major releases.

Warnings

Install

Imports

Quickstart

This example demonstrates how to use `LSCopyAllApplicationURLs` to retrieve a list of all installed applications on macOS and print their file paths. It shows the basic pattern of importing symbols from PyObjC framework bindings.

import objc
from Foundation import NSURL
from LaunchServices import LSCopyAllApplicationURLs

def list_all_applications():
    # LSCopyAllApplicationURLs returns a CFArrayRef of CFURLRefs
    # PyObjC automatically bridges these to Python lists and NSURL objects.
    apps_cf_array = LSCopyAllApplicationURLs(None) # None for all users

    if apps_cf_array:
        app_urls = list(apps_cf_array)
        print(f"Found {len(app_urls)} applications:")
        # Print the paths of the first 5 applications for brevity
        for url in app_urls[:5]:
            print(f"- {url.path()}")
    else:
        print("No applications found or an error occurred.")

if __name__ == "__main__":
    # For simple scripts, direct calls are often sufficient.
    # For UI applications, PyObjC usually runs within a Cocoa event loop.
    list_all_applications()

view raw JSON →