Esempio n. 1
0
 def set_icon(self, file_name):
     try:
         from Cocoa import NSImage, NSWorkspace
         path = (sys._MEIPASS + "/icon.icns/icon.icns") if hasattr(
             sys, "_MEIPASS") else "icon.icns"
         img = NSImage.alloc().initWithContentsOfFile_(str(path))
         NSWorkspace.sharedWorkspace().setIcon_forFile_options_(
             img, str(file_name), 0)
     except ModuleNotFoundError:
         pass  #silent fail writing icon
Esempio n. 2
0
    def __init__(self,
                 paths: list[str],
                 batch_size: int,
                 file_filter: Optional[Callable[[str], bool]],
                 include_mac_packages: bool = False) -> None:
        self.condition = Condition()
        self.paths = paths
        self.batches: list[list[str]] = []
        self.batch_size = batch_size
        self.done = False
        self.errored = False
        self.file_filter = file_filter
        self.batch_buffer_size = 5
        self._pending_batch: list[str] = []
        self._include_mac_packages = include_mac_packages

        if self._include_mac_packages:
            # pylint: disable=useless-suppression
            # pylint: disable=no-name-in-module, import-error
            # noinspection PyUnresolvedReferences
            from Cocoa import NSWorkspace
            self._shared_nsworkspace = NSWorkspace.sharedWorkspace()
            # pylint: enable=useless-suppression
        else:
            self._shared_nsworkspace = None
Esempio n. 3
0
def _screenImageOptions(screen):
    '''
    Process an instance of NSScreen, returning its options as a hash
    '''
    workspace = NSWorkspace.sharedWorkspace()
    if screen == NSScreen.mainScreen():
        is_main = True
    else:
        is_main = False

    screen_options = workspace.desktopImageOptionsForScreen_(screen)
    scaling_factor = screen_options.objectForKey_(
        NSWorkspaceDesktopImageScalingKey)  # NSImageScaling : NSNumber
    allow_clipping = screen_options.objectForKey_(
        NSWorkspaceDesktopImageAllowClippingKey)  # NSNumber
    fill_color = screen_options.objectForKey_(
        NSWorkspaceDesktopImageFillColorKey)  # NSColor
    image_url = workspace.desktopImageURLForScreen_(
        screen).absoluteString()  # NSURL
    options_dict = {
        'main': is_main,
        'scaling_factor': scaling_factor,
        'image_url': image_url,
        'allow_clipping': allow_clipping
    }
    if fill_color:
        options_dict['fill_color'] = {
            'r': fill_color.redComponent(),
            'g': fill_color.greenComponent(),
            'b': fill_color.blueComponent()
        }

    return options_dict
Esempio n. 4
0
def add_workspace_notifications(nsw_config):
    # See http://developer.apple.com/documentation/Cocoa/Conceptual/Workspace/Workspace.html
    notification_center = NSWorkspace.sharedWorkspace().notificationCenter()

    for event in nsw_config:
        event_config = nsw_config[event]

        if "class" in event_config:
            obj         = get_handler_object(event_config['class'])
            objc_method = "on%s:" % event
            py_method   = objc_method.replace(":", "_")
            if not hasattr(obj, py_method) or not callable(getattr(obj, py_method)):
                print  >> sys.stderr, \
                    "NSWorkspace Notification %s: handler class %s must define a %s method" % (event, event_config['class'], py_method)
                sys.exit(1)

            notification_center.addObserver_selector_name_object_(obj, objc_method, event, None)
        else:
            handler          = NotificationHandler.new()
            handler.name     = "NSWorkspace Notification %s" % event
            handler.callable = get_callable_for_event(event, event_config, context=handler.name)

            assert(callable(handler.onNotification_))

            notification_center.addObserver_selector_name_object_(handler, "onNotification:", event, None)
            WORKSPACE_HANDLERS[event] = handler
    log_list("Listening for these NSWorkspace notifications: %s", nsw_config.keys())
Esempio n. 5
0
def add_workspace_notifications(nsw_config):
    # See http://developer.apple.com/documentation/Cocoa/Conceptual/Workspace/Workspace.html
    notification_center = NSWorkspace.sharedWorkspace().notificationCenter()

    for event in nsw_config:
        event_config = nsw_config[event]

        if "class" in event_config:
            obj         = get_handler_object(event_config['class'])
            objc_method = "on%s:" % event
            py_method   = objc_method.replace(":", "_")
            if not hasattr(obj, py_method) or not callable(getattr(obj, py_method)):
                print  >> sys.stderr, \
                    "NSWorkspace Notification %s: handler class %s must define a %s method" % (event, event_config['class'], py_method)
                sys.exit(1)

            notification_center.addObserver_selector_name_object_(obj, objc_method, event, None)
        else:
            handler          = NSNotificationHandler.new()
            handler.name     = "NSWorkspace Notification %s" % event
            handler.callable = get_callable_for_event(event, event_config, context=handler.name)

            assert(callable(handler.onNotification_))

            notification_center.addObserver_selector_name_object_(handler, "onNotification:", event, None)

    log_list("Listening for these NSWorkspace notifications: %s", nsw_config.keys())
Esempio n. 6
0
def frontmost():
    '''
    Get the name of the frontmost application
    '''
    workSpace = NSWorkspace.sharedWorkspace()
    app = workSpace.frontmostApplication()

    return app.localizedName()
Esempio n. 7
0
def frontmost():
    '''
    Get the name of the frontmost application
    '''
    workSpace = NSWorkspace.sharedWorkspace()
    app = workSpace.frontmostApplication()

    return app.localizedName()
Esempio n. 8
0
def add_distributed_notification(event, event_config, dist_center):
    if "class" in event_config:
        obj = get_handler_object(event_config['class'])
        objc_method = "on%s:" % event
        py_method = objc_method.replace(":", "_")

        if not hasattr(obj, py_method) or not callable(getattr(obj,
                                                               py_method)):
            print >> sys.stderr, \
                "NSDistributedNotification %s: handler class %s must define a %s method" % (event, event_config['class'], py_method)
            sys.exit(1)

        dist_center.addObserver_selector_name_object_(obj, objc_method, event,
                                                      None)
    else:
        shouldrm = False
        process_event = {}
        if not event in DISTRIBUTED_IDS:
            DISTRIBUTED_IDS[event] = event_config
            handler = NSNotificationHandler.new()
            handler.name = "NSDistributed %s" % event

            if "process" in event_config:
                notification_center = NSWorkspace.sharedWorkspace(
                ).notificationCenter()
                process_event["process"] = event_config["process"]
                process_event["event"] = event
                process_event["event_config"] = event_config

                logging.info("Adding Process Monitor: %s" %
                             process_event["process"])

                if not event in RELAUNCH_IDS:
                    add_workspace_notification(
                        "NSWorkspaceDidLaunchApplicationNotification",
                        process_event, notification_center)
                    RELAUNCH_IDS[event] = process_event
                else:
                    shouldrm = True

            handler.callable = get_callable_for_event(event,
                                                      event_config,
                                                      context=handler.name)

            assert (callable(handler.onNotification_))

            event_name = event
            if event == '*':
                event_name = None

            if not shouldrm:
                dist_center.addObserver_selector_name_object_(
                    handler, "onNotification:", event_name, None)
            else:
                del DISTRIBUTED_IDS[event]
                dist_center.removeObserver_name_object_(
                    handler, "onNotification", event_name, None)
Esempio n. 9
0
def add_workspace_notifications(nsw_config):
    # See http://developer.apple.com/documentation/Cocoa/Conceptual/Workspace/Workspace.html
    notification_center = NSWorkspace.sharedWorkspace().notificationCenter()
    
    for event in nsw_config:
        event_config = nsw_config[event]
        add_workspace_notification(event, event_config, notification_center)
    
    log_list("Listening for these NSWorkspace notifications: %s", nsw_config.keys())
Esempio n. 10
0
def add_workspace_notifications(nsw_config):
    # See http://developer.apple.com/documentation/Cocoa/Conceptual/Workspace/Workspace.html
    notification_center = NSWorkspace.sharedWorkspace().notificationCenter()

    for event in nsw_config:
        event_config = nsw_config[event]
        add_workspace_notification(event, event_config, notification_center)

    log_list("Listening for these NSWorkspace notifications: %s",
             nsw_config.keys())
Esempio n. 11
0
def search(query):
    '''
    Reveal the finder and search in Spotlight, with the given query.

    CLI Example::

        salt '*' finder.search 'Documents'
    '''
    workSpace = NSWorkspace.sharedWorkspace()
    status = workSpace.showSearchResultsForQueryString_(query)
    return status
Esempio n. 12
0
def add_workspace_notifications(notification_list):
    notification_center = NSWorkspace.sharedWorkspace().notificationCenter()

    for notification in notification_list:
        handler          = NSNotificationHandler.new()
        handler.name     = "NSWorkspace Notification %s" % notification
        handler.callable = get_callable_for_event(notification, context=handler.name)

        assert(callable(handler.onNotification_))

        notification_center.addObserver_selector_name_object_(handler, "onNotification:", notification, None)
Esempio n. 13
0
def search(query):
    '''
    Reveal the finder and search in Spotlight, with the given query.

    CLI Example::

        salt '*' finder.search 'Documents'
    '''
    workSpace = NSWorkspace.sharedWorkspace()
    status = workSpace.showSearchResultsForQueryString_(query)
    return status
Esempio n. 14
0
def launch(application):
    '''
    Open an Application by name.
    This does not need to be the full path to the application, and does not need to have an .app extension.

    CLI Example::

        salt '*' desktop.launch 'TextEdit'
    '''
    workSpace = NSWorkspace.sharedWorkspace()
    status = workSpace.launchApplication_(application)
    return status
Esempio n. 15
0
def open_file(path):
    '''
    Open a file in the current users session (using the default application).
    This requires the full path to the file.

    CLI Example::

        salt '*' desktop.open_file '/Users/Shared'
    '''
    workSpace = NSWorkspace.sharedWorkspace()
    status = workSpace.openFile_(path)
    return status
Esempio n. 16
0
def launch(application):
    '''
    Open an Application by name.
    This does not need to be the full path to the application, and does not need to have an .app extension.

    CLI Example::

        salt '*' desktop.launch 'TextEdit'
    '''
    workSpace = NSWorkspace.sharedWorkspace()
    status = workSpace.launchApplication_(application)
    return status
Esempio n. 17
0
def open_file(path):
    '''
    Open a file in the current users session (using the default application).
    This requires the full path to the file.

    CLI Example::

        salt '*' desktop.open_file '/Users/Shared'
    '''
    workSpace = NSWorkspace.sharedWorkspace()
    status = workSpace.openFile_(path)
    return status
Esempio n. 18
0
def select(path, finder_path=""):
    '''
    Reveal the finder and select the file system object at the given path.
    If the second parameter is specified, a new finder window will be opened at that path.
    Otherwise, an existing finder window will be used.

    CLI Example::

        salt '*' finder.select '/Users/Shared' '/Users'
    '''
    workSpace = NSWorkspace.sharedWorkspace()
    status = workSpace.selectFile_inFileViewerRootedAtPath_(path, finder_path)
    return status
Esempio n. 19
0
def add_workspace_notifications(notification_list):
    notification_center = NSWorkspace.sharedWorkspace().notificationCenter()

    for notification in notification_list:
        handler = NSNotificationHandler.new()
        handler.name = "NSWorkspace Notification %s" % notification
        handler.callable = get_callable_for_event(notification,
                                                  context=handler.name)

        assert (callable(handler.onNotification_))

        notification_center.addObserver_selector_name_object_(
            handler, "onNotification:", notification, None)
Esempio n. 20
0
def select(path, finder_path=""):
    '''
    Reveal the finder and select the file system object at the given path.
    If the second parameter is specified, a new finder window will be opened at that path.
    Otherwise, an existing finder window will be used.

    CLI Example::

        salt '*' finder.select '/Users/Shared' '/Users'
    '''
    workSpace = NSWorkspace.sharedWorkspace()
    status = workSpace.selectFile_inFileViewerRootedAtPath_(path, finder_path)
    return status
Esempio n. 21
0
def processes():
    '''
    Get a list of running processes in the user session

    TODO: optional get by bundle ID
    TODO: optional get hidden
    '''
    workSpace = NSWorkspace.sharedWorkspace()
    appList = workSpace.runningApplications()

    names = [app.localizedName() for app in appList]

    names.sort()
    return names
Esempio n. 22
0
class ApplicationDelegate(NSObject):
    def init(self):
        self = super(ApplicationDelegate, self).init()
        self.hotkeys = dict()
        self.key_hooks = list()
        self.register_hotkey('ctrl-alt- ', self.show_launcher)
        self.register_hotkey('fn-alt-q', self.quit)

        return self

    def applicationDidFinishLaunching_(self, _):
        NSLog("applicationDidFinishLaunching_")

        if not axapi.ax_enabled():
            NSLog("Accessibility Permissions not enabled")

            chili.ui.prompt(
                'Accessibility permissions are required for Chili to run.\n' +
                'The Security preferences will now open, Please go to "Privacy" pane and choose "Accessibility" on the left panel.\n'
                + 'Check the box next to Chili and run the app again.')
            chili.open('/System/Library/PreferencePanes/Security.prefPane')
            self.quit()

            return

        try:
            chili.load_user_settings()
        except Exception, e:
            self.alert_exception(e)

        # launcher window view controller
        self.ctrl = LauncherController.alloc().init()
        self.tap = EventTap(self.global_event, self.should_block_event)

        # regsiter for notifications on deactivated apps
        # this is useful for determining the app that was used
        # before the launcher window was popped up
        delegate = lambda notification: self.notification(notification)
        NSWorkspace.sharedWorkspace().notificationCenter() \
            .addObserverForName_object_queue_usingBlock_(
                'NSWorkspaceDidDeactivateApplicationNotification',
                None, None, delegate)

        chili.set_launcher(self.ctrl)

        n = NSUserNotification.alloc().init()
        n.setTitle_('Chili')
        n.setInformativeText_('Ready')
        NSUserNotificationCenter.defaultUserNotificationCenter() \
            .deliverNotification_(n)
Esempio n. 23
0
def processes():
    '''
    Get a list of running processes in the user session

    TODO: optional get by bundle ID
    TODO: optional get hidden
    '''
    workSpace = NSWorkspace.sharedWorkspace()
    appList = workSpace.runningApplications()

    names = [app.localizedName() for app in appList]

    names.sort()
    return names
Esempio n. 24
0
def add_distributed_notification(event, event_config, dist_center):
    if "class" in event_config:
        obj         = get_handler_object(event_config['class'])
        objc_method = "on%s:" % event
        py_method   = objc_method.replace(":", "_")
        
        if not hasattr(obj, py_method) or not callable(getattr(obj, py_method)):
            print >> sys.stderr, \
                "NSDistributedNotification %s: handler class %s must define a %s method" % (event, event_config['class'], py_method)
            sys.exit(1)
            
        dist_center.addObserver_selector_name_object_(obj, objc_method, event, None)
    else:
        shouldrm = False
        process_event = {}
        if not event in DISTRIBUTED_IDS:
            DISTRIBUTED_IDS[event] = event_config
            handler = NSNotificationHandler.new()
            handler.name = "NSDistributed %s" % event
            
            if "process" in event_config:
                notification_center = NSWorkspace.sharedWorkspace().notificationCenter()
                process_event["process"] = event_config["process"]
                process_event["event"] = event
                process_event["event_config"] = event_config
                
                logging.info("Adding Process Monitor: %s" % process_event["process"])
                
                if not event in RELAUNCH_IDS:
                    add_workspace_notification("NSWorkspaceDidLaunchApplicationNotification", process_event, notification_center)
                    RELAUNCH_IDS[event] = process_event
                else:
                    shouldrm = True
            
            handler.callable = get_callable_for_event(event, event_config, context=handler.name)
            
            assert(callable(handler.onNotification_))
            
            event_name = event
            if event == '*':
                event_name = None
            
            if not shouldrm:
                dist_center.addObserver_selector_name_object_(handler, "onNotification:", event_name, None)
            else:
                del DISTRIBUTED_IDS[event]
                dist_center.removeObserver_name_object_(handler, "onNotification", event_name, None)
Esempio n. 25
0
def add_workspace_notifications(nsw_config):
    # See http://developer.apple.com/documentation/Cocoa/Conceptual/Workspace/Workspace.html
    notification_center = NSWorkspace.sharedWorkspace().notificationCenter()

    class NotificationHandler(NSObject):
        """Simple object for handling NSNotification events"""
        def __init__(self):
            self.callable = compile(
                'raise NotImplementedError("No callable provided!")')

        def onNotification_(self, the_notification):
            if the_notification.userInfo:
                user_info = the_notification.userInfo()
            else:
                user_info = None
            self.callable(user_info=user_info)

    for event in nsw_config:
        event_config = nsw_config[event]

        if "class" in event_config:
            obj = get_handler_object(event_config['class'])
            objc_method = "on%s:" % event
            py_method = objc_method.replace(":", "_")
            if not hasattr(obj, py_method) or not callable(
                    getattr(obj, py_method)):
                print  >> sys.stderr, \
                    "NSWorkspace Notification %s: handler class %s must define a %s method" % (event, event_config['class'], py_method)
                sys.exit(1)

            notification_center.addObserver_selector_name_object_(
                obj, objc_method, event, None)
        else:
            handler = NotificationHandler.new()
            handler.name = "NSWorkspace Notification %s" % event
            handler.callable = get_callable_for_event(event,
                                                      event_config,
                                                      context=handler.name)

            assert (callable(handler.onNotification_))

            notification_center.addObserver_selector_name_object_(
                handler, "onNotification:", event, None)

    log_list("Listening for these NSWorkspace notifications: %s",
             nsw_config.keys())
Esempio n. 26
0
def force_quit(appname, blocking=False):
    '''
    Force an application to quit aka `Force Quit`.
    Does not block until the application quits.

    :param application:
    :return:
    '''
    workSpace = NSWorkspace.sharedWorkspace()
    applications = workSpace.runningApplications()

    for app in applications:
        if app.localizedName() == appname:
            acknowledged = app.forceTerminate()
            return acknowledged

    return None
Esempio n. 27
0
def open_url(url):
    '''
    Open a URL in the current users session.
    This works with anything that command-k would accept, such as:
    afp, smb, vnc, http

    CLI Example::

        salt '*' desktop.open_url 'afp://server.local'
    '''
    workSpace = NSWorkspace.sharedWorkspace()
    url = NSURL.URLWithString_(url)
    if url is None:
        log.error('Invalid URL given: %s' % url)
        return False

    status = workSpace.openURL_(url)
    return status
Esempio n. 28
0
def open_url(url):
    '''
    Open a URL in the current users session.
    This works with anything that command-k would accept, such as:
    afp, smb, vnc, http

    CLI Example::

        salt '*' desktop.open_url 'afp://server.local'
    '''
    workSpace = NSWorkspace.sharedWorkspace()
    url = NSURL.URLWithString_(url)
    if url is None:
        log.error('Invalid URL given: %s' % url)
        return False

    status = workSpace.openURL_(url)
    return status
Esempio n. 29
0
def quit(appname, blocking=False):
    '''
    Ask an application to quit.
    Does not guarantee that the application will quit without user interaction.
    Does not block until the application quits.

    :param application:
    :return:
    '''
    workSpace = NSWorkspace.sharedWorkspace()
    applications = workSpace.runningApplications()

    for app in applications:
        if app.localizedName() == appname:
            acknowledged = app.terminate()
            return acknowledged

    return None
Esempio n. 30
0
def force_quit(appname, blocking=False):
    '''
    Force an application to quit aka `Force Quit`.
    Does not block until the application quits.

    CLI Example::

        salt '*' app.force_quit 'Safari'
    '''
    workSpace = NSWorkspace.sharedWorkspace()
    applications = workSpace.runningApplications()

    for app in applications:
        if app.localizedName() == appname:
            acknowledged = app.forceTerminate()
            return acknowledged

    return None
Esempio n. 31
0
def set_wallpaper(screen_index, path):
    '''
    Set desktop wallpaper for screen at index

    CLI Example:

    .. code-block:: bash

        salt '*' desktop.set_wallpaper 0 '/Library/Desktop Pictures/Solid Colors/Solid Aqua Graphite.png'
    '''
    workspace = NSWorkspace.sharedWorkspace()
    screens = NSScreen.screens()
    screen = screens[screen_index]
    file_url = NSURL.fileURLWithPath_isDirectory_(path, False)
    options = {}

    (status, error) = workspace.setDesktopImageURL_forScreen_options_error_(file_url, screen, options, None)
    return status
Esempio n. 32
0
def set_wallpaper(screen_index, path):
    '''
    Set desktop wallpaper for screen at index

    CLI Example:

    .. code-block:: bash

        salt '*' desktop.set_wallpaper 0 '/Library/Desktop Pictures/Solid Colors/Solid Aqua Graphite.png'
    '''
    workspace = NSWorkspace.sharedWorkspace()
    screens = NSScreen.screens()
    screen = screens[screen_index]
    file_url = NSURL.fileURLWithPath_isDirectory_(path, False)
    options = {}

    (status, error) = workspace.setDesktopImageURL_forScreen_options_error_(
        file_url, screen, options, None)
    return status
Esempio n. 33
0
def quit(appname, blocking=False):
    '''
    Ask an application to quit.
    Does not guarantee that the application will quit without user interaction.
    Does not block until the application quits.

    CLI Example::

        salt '*' app.quit 'Safari'
    '''
    workSpace = NSWorkspace.sharedWorkspace()
    applications = workSpace.runningApplications()

    for app in applications:
        if app.localizedName() == appname:
            acknowledged = app.terminate()
            return acknowledged

    return None
Esempio n. 34
0
def add_workspace_notifications(nsw_config):
    # See http://developer.apple.com/documentation/Cocoa/Conceptual/Workspace/Workspace.html
    notification_center = NSWorkspace.sharedWorkspace().notificationCenter()

    class NotificationHandler(NSObject):
        """Simple object for handling NSNotification events"""

        def __init__(self):
            self.callable = compile('raise NotImplementedError("No callable provided!")')

        def onNotification_(self, the_notification):
            if the_notification.userInfo:
                user_info = the_notification.userInfo()
            else:
                user_info = None
            self.callable(user_info=user_info)


    for event in nsw_config:
        event_config = nsw_config[event]

        if "class" in event_config:
            obj         = get_handler_object(event_config['class'])
            objc_method = "on%s:" % event
            py_method   = objc_method.replace(":", "_")
            if not hasattr(obj, py_method) or not callable(getattr(obj, py_method)):
                print  >> sys.stderr, \
                    "NSWorkspace Notification %s: handler class %s must define a %s method" % (event, event_config['class'], py_method)
                sys.exit(1)

            notification_center.addObserver_selector_name_object_(obj, objc_method, event, None)
        else:
            handler          = NotificationHandler.new()
            handler.name     = "NSWorkspace Notification %s" % event
            handler.callable = get_callable_for_event(event, event_config, context=handler.name)

            assert(callable(handler.onNotification_))

            notification_center.addObserver_selector_name_object_(handler, "onNotification:", event, None)

    log_list("Listening for these NSWorkspace notifications: %s", nsw_config.keys())
Esempio n. 35
0
def _screenImageOptions(screen):
    '''
    Process an instance of NSScreen, returning its options as a hash
    '''
    workspace = NSWorkspace.sharedWorkspace()
    if screen == NSScreen.mainScreen():
        is_main = True
    else:
        is_main = False

    screen_options = workspace.desktopImageOptionsForScreen_(screen)
    scaling_factor = screen_options.objectForKey_(NSWorkspaceDesktopImageScalingKey)  # NSImageScaling : NSNumber
    allow_clipping = screen_options.objectForKey_(NSWorkspaceDesktopImageAllowClippingKey)  # NSNumber
    fill_color = screen_options.objectForKey_(NSWorkspaceDesktopImageFillColorKey)  # NSColor
    image_url = workspace.desktopImageURLForScreen_(screen).absoluteString()  # NSURL
    options_dict = {'main': is_main, 'scaling_factor': scaling_factor, 'image_url': image_url,
                    'allow_clipping': allow_clipping}
    if fill_color:
        options_dict['fill_color'] = {'r': fill_color.redComponent(), 'g': fill_color.greenComponent(),
                                      'b': fill_color.blueComponent()}

    return options_dict
Esempio n. 36
0
 def open(self, path, line):
     from Cocoa import NSWorkspace
     NSWorkspace.sharedWorkspace().openFile_(path)
     return True
Esempio n. 37
0
def labels():
    '''
    Get Finder labels (Not including user defined tags, they are identified by NSURLTagNamesKey)
    '''
    workSpace = NSWorkspace.sharedWorkspace()
    return list(workSpace.fileLabels())
Esempio n. 38
0
def launch(app):
    workspace = NSWorkspace.sharedWorkspace()
    workspace.launchApplication_(app)
Esempio n. 39
0
def open(file):
    workspace = NSWorkspace.sharedWorkspace()
    workspace.openFile_(file)
Esempio n. 40
0
        # Find the path to the just inserted volume
        path = aNotification.userInfo()["NSDevicePath"]

        for aFile in os.listdir(path):
            if readTheseFiles.match(aFile):
                # Found a readme file, try to open it using the Workspace API

                fullPath = os.path.join(path, aFile)
                success, app, _ = workspace.getInfoForFile_application_type_(fullPath)
                if not success:
                    NSLog("Failed to find application to open file %s", fullPath)
                    return
                workspace.openFile_withApplication_(fullPath, app)


# Create an instance of our notification handler, and ask the workspace
# notification center to tell us when a new volume is mounted.
workspace = NSWorkspace.sharedWorkspace()
notificationCenter = workspace.notificationCenter()
notificationHandler = NotificationHandler.new()
notificationCenter.addObserver_selector_name_object_(
    notificationHandler,
    "handleMountNotification:",
    NSWorkspaceDidMountNotification,
    None,
)

NSLog("Listening for mount notifications....")
AppHelper.runConsoleEventLoop()
Esempio n. 41
0
def open_with(file, app):
    workspace = NSWorkspace.sharedWorkspace()
    workspace.openFile_withApplication_(file, app)
Esempio n. 42
0
def open_url(url):
    workspace = NSWorkspace.sharedWorkspace()
    workspace.openURL_(NSURL.URLWithString_(url))
Esempio n. 43
0
def labels():
    '''
    Get Finder labels (Not including user defined tags, they are identified by NSURLTagNamesKey)
    '''
    workSpace = NSWorkspace.sharedWorkspace()
    return list(workSpace.fileLabels())
Esempio n. 44
0
def open_with(file, app):
    workspace = NSWorkspace.sharedWorkspace()
    workspace.openFile_withApplication_(file, app)
Esempio n. 45
0
 def GetForegroundWindow():
     return NSWorkspace.sharedWorkspace().frontmostApplication(
     ).processIdentifier()
Esempio n. 46
0
def open(file):
    workspace = NSWorkspace.sharedWorkspace()
    workspace.openFile_(file)
Esempio n. 47
0
def open_url(url):
    workspace = NSWorkspace.sharedWorkspace()
    workspace.openURL_(NSURL.URLWithString_(url))
Esempio n. 48
0
	def open(self, path, line):
		from Cocoa import NSWorkspace
		NSWorkspace.sharedWorkspace().openFile_(path)
		return True
Esempio n. 49
0
def launch(app):
    workspace = NSWorkspace.sharedWorkspace()
    workspace.launchApplication_(app)