Skip to main content

applaunchservices

Simple package for registering an app with apple Launch Services to handle UTI and URL. See Apple documentations for details.

URL

Launch Services allows a GUI app to register a URL scheme. This means the app can be called when the user types a URL like <scheme>://<something>.

  • set_URL_scheme_handler: Sets the given bundleid as the default handler for a given url scheme.
  • get_URL_scheme_handler: Gets the default bundleid for a given url scheme.
  • open_URL: Opens the given URL with launch services

Files

Launch Services allows a GUI app to register a uniform type identifier (UTI). This means the app can be called when the user double click on a file in the finder that matches this scheme. Or if the user types an url like <file:///path/to/file.ext>.

  • set_UTI_handler: Sets the given bundleid as the default handler for a given uniform type identifier and role.
  • get_UTI_handler: Gets the default bundleid for a given uniform type identifier and role.
  • open_path: Opens the given path with launch services

The roles are:

  • 'none'
  • 'viewer'
  • 'editor'
  • 'shell'
  • 'all'

Bundle Identifier

The bundle identifier is used to identify an app. Two functions are supplied:

  • get_bundle_identifier(): Gets the current bundle identifier if it exists (The app is a GUI app)
  • get_bundle_identifier(pid): Gets the bundle identifier for the given process id if it exists (The app is a GUI app)
  • get_bundle_identifier_for_path(path): Gets the bundle identifier if the path points to a bundle

Usage example:

import applaunchservices as als
from PyQt5.QtWidgets import QApplication, QWidget
from PyQt5.QtCore import QEvent, Qt

# This app opens python scripts as an editor
uniform_type_identifier = "public.python-script"
role = 'editor'


class MacApplication(QApplication):
    """Application that process fileopen events."""
    def event(self, event):
        if event.type() == QEvent.FileOpen:
            widget.setWindowTitle(str(event.file()))
        return QApplication.event(self, event)

# Create application and window
app = MacApplication([''])
widget = QWidget()

# Reset old handler at the end
old_handler = als.get_UTI_handler(uniform_type_identifier, role)
app.aboutToQuit.connect(
    lambda: als.set_UTI_handler(
        uniform_type_identifier, role, old_handler))


# When the app is visible, register itself as a handler
def handle_applicationStateChanged(state):
    if state == Qt.ApplicationActive and app._starting:
        app._starting = False
        bundle_identifier = als.get_bundle_identifier()
        als.set_UTI_handler(
            uniform_type_identifier, role, bundle_identifier)


app._starting = True
app.applicationStateChanged.connect(handle_applicationStateChanged)

# Launch app
widget.setWindowTitle('test')
widget.show()
app.exec_()
# The app can now receive file open events

Metadata

Release files for applaunchservices 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for applaunchservices 0.3.0
File Size Uploaded Provenance Actions
applaunchservices-0.3.0.tar.gz 4.7 kB Without provenance Details for applaunchservices-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for applaunchservices 0.3.0
File Interpreter ABI Platform Actions
applaunchservices-0.3.0-py3-none-any.whl Python 3 none any Details for applaunchservices-0.3.0-py3-none-any.whl

Total release size: 10.4 kB

Release files / applaunchservices-0.3.0.tar.gz

Download URL applaunchservices-0.3.0.tar.gz
Size 4.7 kB
Tags Source
SHA-256 checksum
How to use checksums
1cc6ad5c6c88457230b3cc3d1f76c39c00dcd2597af9c6ee592dce5e67eb2cad
BLAKE2b-256 checksum
How to use checksums
08c1116fae680fceceb75ccb46c089631713f4f7a8a755218f9108aad4aaec54
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.9.12

Release files / applaunchservices-0.3.0-py3-none-any.whl

Download URL applaunchservices-0.3.0-py3-none-any.whl
Size 5.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8c2355bec63fb19aeeea075b89678410a528e2f21dd7b6f6cd2671aed9d8d706
BLAKE2b-256 checksum
How to use checksums
beb9fdcca105aac6410c9dec2f491480743cc06d64d48bed591fc387c4611b1b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.9.12

Security for applaunchservices 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page