Exemplo n.º 1
0
 def register_protocol_handlers(self) -> None:
     """Register the URL scheme listener using PyObjC"""
     bundle_id = NSBundle.mainBundle().bundleIdentifier()
     if bundle_id == "org.python.python":
         log.debug("Skipping URL scheme registration as this program "
                   " was launched from the Python OSX app bundle")
         return
     LSSetDefaultHandlerForURLScheme(self.NXDRIVE_SCHEME, bundle_id)
     log.debug("Registered bundle %r for URL scheme %r", bundle_id,
               self.NXDRIVE_SCHEME)
Exemplo n.º 2
0
def set_default(bundle_id, schemes):
    """Set the default bundle to handle a URI scheme"""
    for scheme in schemes:
        status = LSSetDefaultHandlerForURLScheme(scheme, bundle_id)
        if status == 0:
            puts('set handler for "{}" to "{}"'.format(blue(scheme),
                                                       green(bundle_id)))
        else:
            puts_err(
                red('An error occurred trying to set "{}" '
                    'to handle "{}"'.format(bundle_id, scheme)))
Exemplo n.º 3
0
    def register_protocol_handlers(self):
        """Register the URL scheme listener using PyObjC"""
        from Foundation import NSBundle
        from LaunchServices import LSSetDefaultHandlerForURLScheme

        bundle_id = NSBundle.mainBundle().bundleIdentifier()
        if bundle_id == 'org.python.python':
            log.debug("Skipping URL scheme registration as this program "
                      " was launched from the Python OSX app bundle")
            return
        LSSetDefaultHandlerForURLScheme(self.NXDRIVE_SCHEME, bundle_id)
        log.debug('Registered bundle %r for URL scheme %r', bundle_id,
                  self.NXDRIVE_SCHEME)
Exemplo n.º 4
0
    def make_default(self):
        if self.DEBUG:
            logging.debug("### Reading current browser config")

        httphandler = LSCopyDefaultHandlerForURLScheme("http")
        configpath = expanduser("~/.dockerproxy.conf")

        # If config exists, read it so we can make sure
        # dockerproxy isn't set as default
        if os.path.isfile(configpath):
            config = SafeConfigParser()
            config.read(configpath)
            httphandler = config.get('browser', 'httphandler')

        if "dockerproxy" not in httphandler:
            if self.DEBUG:
                logging.debug(
                    "### Writing current browser details to config file")

            # Assuming same config for all
            newconfig = SafeConfigParser()
            newconfig.add_section("browser")
            newconfig.set('browser', 'httphandler', httphandler)

            with open(configpath, 'w') as f:
                newconfig.write(f)
                f.close()

        if self.DEBUG:
            logging.debug("### Overwriting default browser")

        LSSetDefaultRoleHandlerForContentType("public.html", 0x00000002,
                                              "uk.co.mdsec.osx.dockerproxy")
        LSSetDefaultRoleHandlerForContentType("public.xhtml", 0x00000002,
                                              "uk.co.mdsec.osx.dockerproxy")
        LSSetDefaultHandlerForURLScheme("http", "uk.co.mdsec.osx.dockerproxy")
        LSSetDefaultHandlerForURLScheme("https", "uk.co.mdsec.osx.dockerproxy")
        sys.exit(0)
Exemplo n.º 5
0
    def restore_config(self):
        config = SafeConfigParser()
        configpath = expanduser("~/.dockerproxy.conf")
        logging.debug("### Checking for config")
        if not os.path.isfile(configpath):
            tkMessageBox.showinfo("Error", "Config file does not exist")
            return

        config.read(configpath)
        # Assuming same for all
        httphandler = config.get('browser', 'httphandler')

        if self.DEBUG:
            logging.debug("### Setting original configuration")

        LSSetDefaultRoleHandlerForContentType("public.html", 0x00000002,
                                              httphandler)
        LSSetDefaultRoleHandlerForContentType("public.xhtml", 0x00000002,
                                              httphandler)
        LSSetDefaultHandlerForURLScheme("http", httphandler)
        LSSetDefaultHandlerForURLScheme("https", httphandler)

        sys.exit(0)
Exemplo n.º 6
0
def register_protocol_handlers(controller):
    """Register the URL scheme listener using PyObjC"""
    try:
        from Foundation import NSBundle
        from LaunchServices import LSSetDefaultHandlerForURLScheme
    except ImportError:
        log.warning("Cannot register %r scheme: missing OSX Foundation module",
                    NXDRIVE_SCHEME)
        return

    bundle_id = NSBundle.mainBundle().bundleIdentifier()
    if bundle_id == 'org.python.python':
        log.debug("Skipping URL scheme registration as this program "
                  " was launched from the Python OSX app bundle")
        return
    LSSetDefaultHandlerForURLScheme(NXDRIVE_SCHEME, bundle_id)
    log.debug("Registered bundle '%s' for URL scheme '%s'", bundle_id,
              NXDRIVE_SCHEME)
Exemplo n.º 7
0
    def process(self):
        # Determine the bundle_id of the app path provided
        bundle = NSBundle.bundleWithPath_(self.path)
        if not bundle:
            raise ActionError(
                'unable to locate the bundle id of the app path provided')

        bundle_id = bundle.bundleIdentifier()

        # The user is trying to change the default application for a content type
        if self.content_type:
            # Get the default bundle id for the specified content type
            default_bundle_id = LSCopyDefaultRoleHandlerForContentType(
                self.content_type, kLSRolesAll)
            if not default_bundle_id:
                raise ActionError(
                    'the content type provided could not be found')

            # The current default application matches the one requested
            if default_bundle_id.lower() == bundle_id.lower():
                return self.ok()

            # Change the default application for the specified content type
            LSSetDefaultRoleHandlerForContentType(self.content_type,
                                                  kLSRolesAll, bundle_id)
            return self.changed()

        # The user is trying to change the default application for a URL scheme
        else:
            # Get the default bundle id for the specified url scheme
            default_bundle_id = LSCopyDefaultHandlerForURLScheme(
                self.url_scheme)
            if not default_bundle_id:
                raise ActionError('the url scheme provided could not be found')

            # The current default application matches the one requested
            if default_bundle_id.lower() == bundle_id.lower():
                return self.ok()

            # Change the default application for the specified url scheme
            LSSetDefaultHandlerForURLScheme(self.url_scheme, bundle_id)
            return self.changed()
Exemplo n.º 8
0
def set_URL_scheme_handler(url_scheme, bundle_identifier):
    """Set handler for given URL scheme."""
    LSSetDefaultHandlerForURLScheme(url_scheme, bundle_identifier)
Exemplo n.º 9
0
#!/usr/bin/python
from LaunchServices import LSSetDefaultHandlerForURLScheme
from LaunchServices import LSSetDefaultRoleHandlerForContentType

# 0x00000002 = kLSRolesViewer
# see https://developer.apple.com/library/mac/#documentation/Carbon/Reference/LaunchServicesReference/Reference/reference.html#//apple_ref/c/tdef/LSRolesMask
LSSetDefaultRoleHandlerForContentType("public.html", 0x00000002,
                                      "com.google.chrome")
LSSetDefaultRoleHandlerForContentType("public.xhtml", 0x00000002,
                                      "com.google.chrome")
LSSetDefaultHandlerForURLScheme("http", "com.google.chrome")
LSSetDefaultHandlerForURLScheme("https", "com.google.chrome")
Exemplo n.º 10
0
#/usr/bin/env python
from LaunchServices import LSSetDefaultHandlerForURLScheme
from LaunchServices import LSSetDefaultRoleHandlerForContentType

# 0x00000002 = kLSRolesViewer
# see https://developer.apple.com/library/mac/#documentation/Carbon/Reference/LaunchServicesReference/Reference/reference.html#//apple_ref/c/tdef/LSRolesMask
LSSetDefaultRoleHandlerForContentType("public.html", 0x00000002,
                                      "com.operasoftware.operanext")
LSSetDefaultRoleHandlerForContentType("public.xhtml", 0x00000002,
                                      "com.operasoftware.operanext")
LSSetDefaultHandlerForURLScheme("http", "com.operasoftware.operanext")
LSSetDefaultHandlerForURLScheme("https", "com.operasoftware.operanext")