当前位置: 首页>>代码示例>>Python>>正文


Python NSWorkspace.sharedWorkspace方法代码示例

本文整理汇总了Python中AppKit.NSWorkspace.sharedWorkspace方法的典型用法代码示例。如果您正苦于以下问题:Python NSWorkspace.sharedWorkspace方法的具体用法?Python NSWorkspace.sharedWorkspace怎么用?Python NSWorkspace.sharedWorkspace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AppKit.NSWorkspace的用法示例。


在下文中一共展示了NSWorkspace.sharedWorkspace方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: suspend_apps

# 需要导入模块: from AppKit import NSWorkspace [as 别名]
# 或者: from AppKit.NSWorkspace import sharedWorkspace [as 别名]
def suspend_apps(app_names):
    '''
    Suspend apps of given names
    :param app_names: {List[String]} list of app names 
    '''
    previous_app = None
    while True:
        app = Application(NSWorkspace.sharedWorkspace().activeApplication())
        if previous_app != app:
            logger.debug('Currently focused on %s', app.name)
            if app.name in app_names:
                app.resume()
            if previous_app and previous_app.name in app_names:
                previous_app.suspend()
            previous_app = app
        time.sleep(0.7) 
开发者ID:omikun,项目名称:ForceNap,代码行数:18,代码来源:nap_my_app.py

示例2: game_running

# 需要导入模块: from AppKit import NSWorkspace [as 别名]
# 或者: from AppKit.NSWorkspace import sharedWorkspace [as 别名]
def game_running(self):

        if platform == 'darwin':
            for app in NSWorkspace.sharedWorkspace().runningApplications():
                if app.bundleIdentifier() == 'uk.co.frontier.EliteDangerous':
                    return True

        elif platform == 'win32':

            def WindowTitle(h):
                if h:
                    l = GetWindowTextLength(h) + 1
                    buf = ctypes.create_unicode_buffer(l)
                    if GetWindowText(h, buf, l):
                        return buf.value
                return None

            def callback(hWnd, lParam):
                name = WindowTitle(hWnd)
                if name and name.startswith('Elite - Dangerous'):
                    handle = GetProcessHandleFromHwnd(hWnd)
                    if handle:	# If GetProcessHandleFromHwnd succeeds then the app is already running as this user
                        CloseHandle(handle)
                        return False	# stop enumeration
                return True

            return not EnumWindows(EnumWindowsProc(callback), 0)

        return False


    # Return a subset of the received data describing the current ship as a Loadout event 
开发者ID:EDCD,项目名称:EDMarketConnector,代码行数:34,代码来源:monitor.py

示例3: _handler

# 需要导入模块: from AppKit import NSWorkspace [as 别名]
# 或者: from AppKit.NSWorkspace import sharedWorkspace [as 别名]
def _handler(self, event):
            # use event.charactersIgnoringModifiers to handle composing characters like Alt-e
            if (event.modifierFlags() & HotkeyMgr.MODIFIERMASK) == self.modifiers and ord(event.charactersIgnoringModifiers()[0]) == self.keycode:
                if config.getint('hotkey_always'):
                    self.activated = True
                else:	# Only trigger if game client is front process
                    front = NSWorkspace.sharedWorkspace().frontmostApplication()
                    if front and front.bundleIdentifier() == 'uk.co.frontier.EliteDangerous':
                        self.activated = True 
开发者ID:EDCD,项目名称:EDMarketConnector,代码行数:11,代码来源:hotkey.py

示例4: my_app_nap

# 需要导入模块: from AppKit import NSWorkspace [as 别名]
# 或者: from AppKit.NSWorkspace import sharedWorkspace [as 别名]
def my_app_nap():
    prev_app = None
    while True:
        cur_app = NSWorkspace.sharedWorkspace().activeApplication()
        if settings_updated[0]:
            print("settings update detected in my_app_nap()")
            on_update_settings(launchedApps, cur_app)
        if prev_app != cur_app:
            if cur_app['NSApplicationName'] in sucky_app_names:
                resume(cur_app)
            if prev_app and prev_app['NSApplicationName'] in sucky_app_names:
                suspend(prev_app)
            prev_app = cur_app
        time.sleep(0.5) 
开发者ID:omikun,项目名称:ForceNap,代码行数:16,代码来源:ForceNap.py

示例5: suspend_background_apps

# 需要导入模块: from AppKit import NSWorkspace [as 别名]
# 或者: from AppKit.NSWorkspace import sharedWorkspace [as 别名]
def suspend_background_apps():
    '''
    Suspends all apps except app in focus
    '''
    previous_app = None
    while True:
        app = Application(NSWorkspace.sharedWorkspace().activeApplication())
        if previous_app is None:
            previous_app = app
        if previous_app and app != previous_app:
            previous_app.suspend()
        app.resume()
        previous_app = app
        time.sleep(0.7) 
开发者ID:omikun,项目名称:ForceNap,代码行数:16,代码来源:nap_my_app.py

示例6: close_window

# 需要导入模块: from AppKit import NSWorkspace [as 别名]
# 或者: from AppKit.NSWorkspace import sharedWorkspace [as 别名]
def close_window(self):
        workspace = NSWorkspace.sharedWorkspace()
        activeApps = workspace.runningApplications()

        for app in activeApps:
            if app.isActive() and app.localizedName() == "Blizzard Battle.net":
                app.hide() 
开发者ID:bartok765,项目名称:galaxy_blizzard_plugin,代码行数:9,代码来源:local_client.py

示例7: prevent_battlenet_from_showing

# 需要导入模块: from AppKit import NSWorkspace [as 别名]
# 或者: from AppKit.NSWorkspace import sharedWorkspace [as 别名]
def prevent_battlenet_from_showing(self):
        client_popup_wait_time = 5
        check_frequency_delay = 0.02

        workspace = NSWorkspace.sharedWorkspace()
        activeApps = workspace.runningApplications()

        end_time = time() + client_popup_wait_time
        while time() <= end_time:
            for app in activeApps:
                if app.isActive() and app.localizedName() == "Blizzard Battle.net":
                    app.hide()
                    return
            await asyncio.sleep(check_frequency_delay)
        log.info("Timed out on prevent battlenet from showing") 
开发者ID:bartok765,项目名称:galaxy_blizzard_plugin,代码行数:17,代码来源:local_client.py

示例8: get_app_name

# 需要导入模块: from AppKit import NSWorkspace [as 别名]
# 或者: from AppKit.NSWorkspace import sharedWorkspace [as 别名]
def get_app_name(bundle_id):
    '''Get display name for app specified by bundle_id'''
    from AppKit import NSWorkspace
    from Foundation import NSFileManager
    app_path = NSWorkspace.sharedWorkspace(
        ).absolutePathForAppBundleWithIdentifier_(bundle_id)
    if app_path:
        return NSFileManager.defaultManager().displayNameAtPath_(app_path)
    return bundle_id 
开发者ID:jacobsalmela,项目名称:NCutil,代码行数:11,代码来源:NCutil.py

示例9: get_bundle_id

# 需要导入模块: from AppKit import NSWorkspace [as 别名]
# 或者: from AppKit.NSWorkspace import sharedWorkspace [as 别名]
def get_bundle_id(app_name):
    '''Given an app_name, get the bundle_id'''
    from AppKit import NSWorkspace
    from Foundation import NSBundle
    app_path = NSWorkspace.sharedWorkspace(
        ).fullPathForApplication_(app_name)
    if app_path:
        return NSBundle.bundleWithPath_(app_path).bundleIdentifier()
    return None


# flags are bits in a 16 bit(?) data structure 
开发者ID:jacobsalmela,项目名称:NCutil,代码行数:14,代码来源:NCutil.py

示例10: get_running_apps

# 需要导入模块: from AppKit import NSWorkspace [as 别名]
# 或者: from AppKit.NSWorkspace import sharedWorkspace [as 别名]
def get_running_apps():
    """Return a list of running applications"""
    procs = []
    workspace = NSWorkspace.sharedWorkspace()
    running_apps = workspace.runningApplications()
    for app in running_apps:
        procs.append(app.localizedName())
    return procs 
开发者ID:haircut,项目名称:better-jamf-policy-deferral,代码行数:10,代码来源:better-jamf-policy-deferral.py

示例11: install_notifier

# 需要导入模块: from AppKit import NSWorkspace [as 别名]
# 或者: from AppKit.NSWorkspace import sharedWorkspace [as 别名]
def install_notifier():
    """Extract ``Notify.app`` from the workflow to data directory.

    Changes the bundle ID of the installed app and gives it the
    workflow's icon.
    """
    archive = os.path.join(os.path.dirname(__file__), 'Notify.tgz')
    destdir = wf().datadir
    app_path = os.path.join(destdir, 'Notify.app')
    n = notifier_program()
    log().debug('installing Notify.app to %r ...', destdir)
    # z = zipfile.ZipFile(archive, 'r')
    # z.extractall(destdir)
    tgz = tarfile.open(archive, 'r:gz')
    tgz.extractall(destdir)
    assert os.path.exists(n), \
        'Notify.app could not be installed in %s' % destdir

    # Replace applet icon
    icon = notifier_icon_path()
    workflow_icon = wf().workflowfile('icon.png')
    if os.path.exists(icon):
        os.unlink(icon)

    png_to_icns(workflow_icon, icon)

    # Set file icon
    # PyObjC isn't available for 2.6, so this is 2.7 only. Actually,
    # none of this code will "work" on pre-10.8 systems. Let it run
    # until I figure out a better way of excluding this module
    # from coverage in py2.6.
    if sys.version_info >= (2, 7):  # pragma: no cover
        from AppKit import NSWorkspace, NSImage

        ws = NSWorkspace.sharedWorkspace()
        img = NSImage.alloc().init()
        img.initWithContentsOfFile_(icon)
        ws.setIcon_forFile_options_(img, app_path, 0)

    # Change bundle ID of installed app
    ip_path = os.path.join(app_path, 'Contents/Info.plist')
    bundle_id = '{0}.{1}'.format(wf().bundleid, uuid.uuid4().hex)
    data = plistlib.readPlist(ip_path)
    log().debug('changing bundle ID to %r', bundle_id)
    data['CFBundleIdentifier'] = bundle_id
    plistlib.writePlist(data, ip_path) 
开发者ID:TKkk-iOSer,项目名称:wechat-alfred-workflow,代码行数:48,代码来源:notify.py

示例12: install_notifier

# 需要导入模块: from AppKit import NSWorkspace [as 别名]
# 或者: from AppKit.NSWorkspace import sharedWorkspace [as 别名]
def install_notifier():
    """Extract `Notify.app` from the workflow to data directory.

    Changes the bundle ID of the installed app and gives it the
    workflow's icon.
    """
    archive = os.path.join(os.path.dirname(__file__), 'Notify.tgz')
    destdir = wf().datadir
    app_path = os.path.join(destdir, 'Notify.app')
    n = notifier_program()
    log().debug("Installing Notify.app to %r ...", destdir)
    # z = zipfile.ZipFile(archive, 'r')
    # z.extractall(destdir)
    tgz = tarfile.open(archive, 'r:gz')
    tgz.extractall(destdir)
    assert os.path.exists(n), (
        "Notify.app could not be installed in {0!r}.".format(destdir))

    # Replace applet icon
    icon = notifier_icon_path()
    workflow_icon = wf().workflowfile('icon.png')
    if os.path.exists(icon):
        os.unlink(icon)

    png_to_icns(workflow_icon, icon)

    # Set file icon
    # PyObjC isn't available for 2.6, so this is 2.7 only. Actually,
    # none of this code will "work" on pre-10.8 systems. Let it run
    # until I figure out a better way of excluding this module
    # from coverage in py2.6.
    if sys.version_info >= (2, 7):  # pragma: no cover
        from AppKit import NSWorkspace, NSImage

        ws = NSWorkspace.sharedWorkspace()
        img = NSImage.alloc().init()
        img.initWithContentsOfFile_(icon)
        ws.setIcon_forFile_options_(img, app_path, 0)

    # Change bundle ID of installed app
    ip_path = os.path.join(app_path, 'Contents/Info.plist')
    bundle_id = '{0}.{1}'.format(wf().bundleid, uuid.uuid4().hex)
    data = plistlib.readPlist(ip_path)
    log().debug('Changing bundle ID to {0!r}'.format(bundle_id))
    data['CFBundleIdentifier'] = bundle_id
    plistlib.writePlist(data, ip_path) 
开发者ID:danielecook,项目名称:Quiver-alfred,代码行数:48,代码来源:notify.py


注:本文中的AppKit.NSWorkspace.sharedWorkspace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。