PyObjC Framework DictionaryServices

12.1 · active · verified Tue Apr 14

pyobjc-framework-dictionaryservices provides Python wrappers for the macOS DictionaryServices framework, enabling Python applications to interact with the system's dictionary and thesaurus. It is part of the larger PyObjC project, which actively maintains bindings for various macOS frameworks, with releases typically tied to new macOS SDKs and Python version support. The current version is 12.1.

Warnings

Install

Imports

Quickstart

This example demonstrates how to use the macOS DictionaryServices framework via PyObjC to look up the definition of a word. It uses `DCSCopyTextDefinition` which is accessed through the `CoreServices` package.

import Foundation
import CoreServices
import objc

word = "recursive"

# Create a CFStringRef from a Python string
string_ref = Foundation.CFString.stringWithString_(word)

# Define a range covering the entire string
full_range = CoreServices.CFRange(0, len(word))

# Look up the definition using DCSCopyTextDefinition
definition_ref = CoreServices.DCSCopyTextDefinition(string_ref, full_range)

if definition_ref:
    # Convert CFStringRef to Python string and print
    definition = str(definition_ref)
    print(f"Definition of '{word}':\n{definition}")
    # Release the CFStringRef returned by DCSCopyTextDefinition (retained by 'Copy')
    Foundation.CFRelease(definition_ref)
else:
    print(f"No definition found for '{word}'.")

# Release the input CFStringRef
Foundation.CFRelease(string_ref)

view raw JSON →