dooti API

Module contents

exception dooti.ApplicationNotFound[source]

Bases: ValueError

Raised when a handler reference cannot be resolved.

exception dooti.BundleURLNotFound[source]

Bases: ApplicationNotFound

Raised when a bundle ID is not registered on the system.

class dooti.Dooti(workspace=None)[source]

Bases: object

Wrapper for macOS system API to manage default handlers on macOS 12.0+.

bundle_to_url(bundle_id: str) NSURL[source]

Returns a URL (filesystem path prefixed with ‘file://’ scheme) to an application with the specified bundle ID.

Parameters:

bundle_id (str) – bundle ID to look up the URL for

Raises:

BundleURLNotFound: when no application with specified bundle ID was found

static ext_to_utis(ext: str) NSArray[source]

Returns all UTI associated with specified file extension. If the extension is not registered with MacOS, will return a dynamic UTI as first and only element.

Parameters:

ext (str) – file extension to look up associated UTI for

get_app_path(app: str) NSURL[source]

Returns a URL (filesystem path prefixed with ‘file://’ scheme) to an application specified by name, absolute path or bundle ID.

Parameters:

app (str) – name, absolute filesystem path or bundle ID to look up the URL for

Raises:

ApplicationNotFound: when no matching application was found

get_default_ext(ext: str) str | None[source]

Returns the filesystem path to the default handler for the specified file extension.

Parameters:

ext (str) – filename extension to look up the default handler path for

get_default_scheme(scheme: str) str | None[source]

Returns the filesystem path to the default handler for the specified URL scheme.

Parameters:

ext (str) – filename extension to look up the default handler path for

get_default_uti(uti: str | UTType) str | None[source]

Returns the filesystem path to the default handler for the specified UTI.

Parameters:

uti (str | UTType) – UTI to look up the default handler path for

is_dynamic_uti(ext_or_uti: str | UTType) bool[source]

Checks whether a UTI is dynamic/whether a file extension is not associated with at least one registered UTI.

Parameters:

ext_or_uti (str | UTType) – UTI or file extension to check

name_to_url(app_name: str) NSURL[source]

Returns a URL (filesystem path prefixed with ‘file://’ scheme) to an application with the specified name.

Parameters:

app_name (str) – application name to look up the URL for

Raises:

ApplicationNotFound: when no application with specified bundle ID was found

path_to_url(path: str, skip_check: bool = False) NSURL[source]

Translates an absolute filesystem path to a URL.

Parameters:
  • path (str) – absolute filesystem path to translate

  • skip_check (bool) – override check if the target exists and is a directory

Raises:

ApplicationNotFound: when no application with specified bundle ID was found

set_default_ext(ext: str, app: str, allow_dynamic: bool = False) None[source]

Sets a default handler for all UTI registered to a file extension.

Parameters:
  • ext (str) – file extension to set the default handler for

  • app (str) – absolute filesystem path, name or bundle ID of the handler

  • allow_dynamic (bool) – whether to allow dynamic UTIs (default False)

Raises:

ExtHasNoRegisteredUTI if the file extension is unknown to MacOS and not allowing dynamic UTI

set_default_scheme(scheme: str, app: str) None[source]

Sets a default handler for a specific URL scheme.

Parameters:
  • scheme (str) – URL scheme to set the default handler for

  • app (str) – absolute filesystem path, name or bundle ID of the handler

set_default_uti(uti: str | UTType, app: str) None[source]

Sets a default handler for a specific UTI.

Parameters:
  • uti (str | UTType) – UTI to set the default handler for

  • app (str) – absolute filesystem path, name or bundle ID of the handler

exception dooti.ExtHasNoRegisteredUTI[source]

Bases: ValueError

Raised when trying to set a handler for a file extension that does not have an associated registered UTI.