xcallback

Opening x-callback URLs

This module is used to interact with other apps with x-callback URLs.

xcallback.open_url(url: str) → str

Opens the given x-callback URL. The function will return only if the request was successfully completed.

Raises: RuntimeError if there was an error and SystemExit if the request was cancelled. Returns: The result sent by the opened app.

Parameters:url – The URL to open.
Return type:str

Example with Shortcuts

"""
Opens a Shortcut and retrieves the result.
"""

import xcallback
from urllib.parse import quote

shortcut_name = input("The name of the shortcut to open: ")
shortcut_input = input("What would you like to send to the Shortcut? ")

# https://support.apple.com/guide/shortcuts/apdcd7f20a6f/ios
url = f"shortcuts://x-callback-url/run-shortcut?name={quote(shortcut_name)}&input=text&text={quote(shortcut_input)}"

try:
    res = xcallback.open_url(url) # If successed, returns the result
    print("Result:\n"+res)
except RuntimeError as e:
    print("Error: "+str(e)) # If failed, raises ``RuntimeError``
except SystemExit:
    print("Cancelled") # If cancelled, raises ``SystemExit``