예제 #1
0
def update_running_list():
    global running_application_dict
    running_application_dict = {}
    running = {}
    for cur_app in ui.apps(background=False):
        running_application_dict[cur_app.name] = True

        if app.platform == "windows":
            # print("hit....")
            # print(cur_app.exe)
            running_application_dict[cur_app.exe.split(os.path.sep)[-1]] = True

    running = actions.user.create_spoken_forms_from_list(
        [curr_app.name for curr_app in ui.apps(background=False)],
        words_to_exclude=words_to_exclude,
        generate_subsequences=True,
    )

    # print(str(running_application_dict))
    # todo: should the overrides remove the other spoken forms for an application?
    for override in overrides:
        if overrides[override] in running_application_dict:
            running[override] = overrides[override]

    lists = {
        "self.running": running,
    }

    # batch update lists
    ctx.lists.update(lists)
예제 #2
0
def switch_app(m, name=None, word_index=None, last=False):
    '''word_index determines which word in the phrase is the app name'''
    if not word_index and not name:
        raise Exception(
            'If the app name is not supplied, a word index must be supplied')

    if word_index:
        name = str(m._words[word_index])

    full = apps.get(name)
    if not full:
        return

    for app in ui.apps():
        if app.name == full:
            app.focus()
            timestamp = time.time()
            while True:
                if ui.active_app().name == full:
                    break
                if time.time() - timestamp > 5:
                    raise Exception(
                        '{} could not be focused within five seconds. Giving up.'
                        .format(full))
                time.sleep(0.03)
            break
예제 #3
0
    def switcher_focus(name: str):
        """Focus a new application by  name"""

        wanted_app = name

        # we should use the capture result directly if it's already in the
        # list of running applications
        # otherwise, name is from <user.text> and we can be a bit fuzzier
        if name not in running_application_dict:

            # don't process silly things like "focus i"
            if len(name) < 3:
                print("switcher_focus skipped: len({}) < 3".format(name))
                return

            running = ctx.lists["self.running"]
            wanted_app = None

            for running_name in running.keys():

                if running_name == name or running_name.lower().startswith(
                        name.lower()):
                    wanted_app = running[running_name]
                    break

            if wanted_app is None:
                return

        for cur_app in ui.apps():
            if cur_app.name == wanted_app and not cur_app.background:
                cur_app.focus()
                break
예제 #4
0
def shell_rerun(m):
    # switch_app(name='iTerm2')
    app = ui.apps(bundle="io.alacritty")[0]
    ctrl.key_press("c", ctrl=True, app=app)
    time.sleep(0.05)
    ctrl.key_press("up", app=app)
    ctrl.key_press("enter", app=app)
예제 #5
0
def update_lists():
    new = {}
    for app in ui.apps():
        if app.background and not app.windows():
            continue
        words = app.name.lower().split(' ')
        for word in words:
            if word and not word in new:
                new[word] = app.bundle
        new[app.name] = app.bundle
    ctx.lists['self.running'] = new

    new = {}
    for base in '/Applications', '/Applications/Utilities':
        for name in os.listdir(base):
            path = os.path.join(base, name)
            name = name.rsplit('.', 1)[0].lower()
            new[name] = path
            words = name.split(' ')
            for word in words:
                if word and word not in new:
                    if len(name) > 6 and len(word) < 3:
                        continue
                    new[word] = path
    ctx.lists['self.launch'] = new
예제 #6
0
def update_lists():
    global running_application_dict
    running_application_dict = {}
    running = {}
    for cur_app in ui.apps(background=False):
        name = cur_app.name

        if name.endswith(".exe"):
            name = name.rsplit(".", 1)[0]

        words = get_words(name)
        for word in words:
            if word and word not in running and len(word) >= 3:
                running[word.lower()] = cur_app.name

        running[name.lower()] = cur_app.name
        running_application_dict[cur_app.name] = True

    for override in overrides:
        running[override] = overrides[override]

    lists = {
        "self.running": running,
        # "self.launch": launch,
    }

    # batch update lists
    ctx.lists.update(lists)
예제 #7
0
def shell_rerun(m):
    # switch_app(name='iTerm2')
    app = ui.apps(bundle="com.googlecode.iterm2")[0]
    ctrl.key_press("c", ctrl=True, app=app)
    time.sleep(0.05)
    ctrl.key_press("up", app=app)
    ctrl.key_press("enter", app=app)
예제 #8
0
 def switcher_focus(name: str):
     """Focus a new application by  name"""
     for app in ui.apps():
         # print(f"--------- app.name:{app.name}  app.bundler:{app.bundle}")
         if name in app.name and not app.background:
             app.focus()
             break
예제 #9
0
def update_lists():
    global running
    global launch
    new = {}
    for app in ui.apps():
        if app.background and not app.windows():
            continue
        words = app.name.split(' ')
        for word in words:
            if word and not word in new:
                new[word] = app.name
        new[app.name] = app.name
    running = new
    ctx.set_list('running', running.keys())

    new = {}
    for base in '/Applications', '/Applications/Utilities':
        for name in os.listdir(base):
            path = os.path.join(base, name)
            name = name.rsplit('.', 1)[0]
            new[name.lower()] = path.lower()
            words = name.split(' ')
            for word in words:
                if word and word not in new:
                    if len(name) > 6 and len(word) < 3:
                        continue
                    new[word.lower()] = path.lower()
    launch = new
    ctx.set_list('launch', launch.keys())
예제 #10
0
def update_lists():
    new = {}
    for cur_app in ui.apps(background=False):
        name = cur_app.name
        if name.endswith('.exe'):
            name = name.rsplit('.', 1)[0]
        words = get_words(name)
        for word in words:
            if word and not word in new:
                new[word.lower()] = cur_app.name
        new[name.lower()] = cur_app.name
    for override in overrides:
        new[override] = overrides[override]

    ctx.lists['self.running'] = new

    #print(str(new))
    new = {}

    if app.platform == "mac":
        for base in '/Applications', '/Applications/Utilities':
            for name in os.listdir(base):
                path = os.path.join(base, name)
                name = name.rsplit('.', 1)[0].lower()
                new[name] = path
                words = name.split(' ')
                for word in words:
                    if word and word not in new:
                        if len(name) > 6 and len(word) < 3:
                            continue
                        new[word] = path

        ctx.lists['self.launch'] = new
예제 #11
0
def update_lists():
    global running
    global launch
    new = {}
    for app in ui.apps():
        if app.background and not app.windows():
            continue
        words = app.name.split(" ")
        for word in words:
            if word and word not in new:
                new[word] = app.name
        new[app.name] = app.name
    running = new
    running.update(hardcoded_application_names)
    ctx.set_list("running", running.keys())

    new = {}
    for base in "/Applications", "/Applications/Utilities", "/System/Applications", "/System/Applications/Utilities":
        for name in os.listdir(base):
            path = os.path.join(base, name)
            name = name.rsplit(".", 1)[0]
            new[name] = path
            words = name.split(" ")
            for word in words:
                if word and word not in new:
                    if len(name) > 6 and len(word) < 3:
                        continue
                    new[word] = path
    launch = new
    ctx.set_list("launch", launch.keys())
예제 #12
0
 def shell_rerun():
     """rerun the most recent command in whichever shell as most recently used"""
     # switch_app(name='iTerm2')
     app = ui.apps(bundle="com.googlecode.iterm2")[0]
     ctrl.key_press("c", ctrl=True, app=app)
     actions.sleep("50ms")
     ctrl.key_press("up", app=app)
     ctrl.key_press("enter", app=app)
예제 #13
0
 def switcher_focus(name: str):
     """Focus a new application by  name"""
     for app in ui.apps():
         #print("app.name:" + app.name)
         #print("app.bundler: " + app.bundle)
         if app.name == name and not app.background:
             app.focus()
             break
예제 #14
0
def switch_app(m):
    name = str(m._words[1])
    full = apps.get(name)
    if not full: return
    for app in ui.apps():
        if app.name == full:
            app.focus()
            break
예제 #15
0
def get_editor_app() -> ui.App:
    editor_names = get_editor_names()

    for app in ui.apps(background=False):
        if app.name in editor_names:
            return app

    actions.user.system_command("code")
    while True:
        actions.sleep("500ms")

        for app in ui.apps(background=False):
            if app.name in editor_names:
                return app


    raise RuntimeError("Draft editor is not running")
예제 #16
0
def scope():
    editor_names = get_editor_names()

    for app in ui.apps(background=False):
        if app.name in editor_names:
            return {"draft_editor_running": True}

    return {"draft_editor_running": False}
예제 #17
0
def get_editor_app() -> ui.App:
    editor_names = get_editor_names()

    for app in ui.apps(background=False):
        if app.name in editor_names:
            return app

    raise RuntimeError("Draft editor is not running")
예제 #18
0
 def focus(name: str):
     """Focus a new application by  name"""
     full = ctx.lists['self.running'].get(name)
     if not full:
         return
     for app in ui.apps():
         if app.name == full and not app.background:
             app.focus()
             break
예제 #19
0
def update_running_applications_list():
    running = {}

    for cur_app in ui.apps(background=False):
        name = cur_app.name
        running[name.lower()] = name

    mod.list('running', desc='List of currently running applications')
    ctx.lists['self.running'] = running
예제 #20
0
def switch_app(m):
    name = str(m['switcher.running'][0])
    full = running.get(name)
    if not full: return
    for app in ui.apps():
        if app.name == full:
            app.focus()
            # TODO: replace sleep with a check to see when it is in foreground
            time.sleep(0.25)
            break
예제 #21
0
def switch_app(m):
    # noinspection PyProtectedMember
    name = parse_word(m._words[1])
    full = apps.get(name)
    if not full:
        return
    for app in ui.apps():
        if app.name == full:
            app.focus()
            break
예제 #22
0
def switch_app(m):
    name = str(m._words[1])
    full = apps.get(name)
    if not full: return
    for app in ui.apps():
        if app.name == full:
            app.focus()
            # TODO: replace sleep with a check to see when it is in foreground
            time.sleep(0.25)
            break
예제 #23
0
def switch_app(m, name=None):  # jsc modified for single-word shortcut
    if name is None:
        name = str(m._words[1])
    full = apps.get(name)
    if not full: return
    for app in ui.apps():
        if app.name == full:
            app.focus()
            # TODO: replace sleep with a check to see when it is in foreground
            time.sleep(0.25)
            break
예제 #24
0
def update_lists():
    global running_application_dict
    running_application_dict = {}
    for cur_app in ui.apps(background=False):
        running_application_dict[cur_app.name] = True

    running = actions.user.create_spoken_forms_from_list(
        [curr_app.name for curr_app in ui.apps(background=False)],
        words_to_exclude=words_to_exclude,
    )

    for override in overrides:
        running[override] = overrides[override]

    lists = {
        "self.running": running,
        # "self.launch": launch,
    }

    # batch update lists
    ctx.lists.update(lists)
예제 #25
0
 def focus(bundle: str):
     """Focus a new application by bundle name"""
     app = ui.apps(bundle=bundle)
     if app:
         app = app[0]
         app.focus()
         # TODO: replace sleep with a registered callback
         for i in range(25):
             if ui.active_app().bundle == bundle:
                 break
             time.sleep(0.01)
         time.sleep(0.05)
예제 #26
0
def lookup_app(m=None, name=None):
    if isinstance(m, str):
        name = m
    elif name is None:
        name = str(m["switcher.running"][0])

    full = running.get(name)
    if not full:
        return
    for app in ui.apps():
        if app.name == full:
            return app
예제 #27
0
def switch_app(m, name=None):
    if name is None:
        name = str(m['switcher.running'][0])
    full = running.get(name)
    if not full: return
    for app in ui.apps():
        if app.name == full:
            app.focus()
            # TODO: replace sleep with a check to see when it is in foreground
            time.sleep(0.25)
            break
    move_mouse_to_center_of_application()
예제 #28
0
def update_lists():
    global apps
    new = {}
    for app in ui.apps():
        words = app.name.split(' ')
        for word in words:
            if word and not word in new:
                new[word] = app.name
        new[app.name] = app.name
    if set(new.keys()) == set(apps.keys()):
        return
    ctx.set_list('apps', new.keys())
    apps = new
예제 #29
0
def update_lists():
    global running_application_dict
    running_application_dict = {}
    running = {}
    launch = {}
    for cur_app in ui.apps(background=False):
        name = cur_app.name

        if name.endswith(".exe"):
            name = name.rsplit(".", 1)[0]

        words = get_words(name)
        for word in words:
            if word and word not in running:
                running[word.lower()] = cur_app.name

        running[name.lower()] = cur_app.name
        running_application_dict[cur_app.name] = True

    for override in overrides:
        running[override] = overrides[override]

    if app.platform == "mac":
        for base in (
                "/Applications",
                "/Applications/Utilities",
                "/System/Applications",
                "/System/Applications/Utilities",
        ):
            if os.path.isdir(base):
                for name in os.listdir(base):
                    # print(name)
                    path = os.path.join(base, name)
                    name = name.rsplit(".", 1)[0].lower()
                    launch[name] = path
                    words = name.split(" ")
                    for word in words:
                        if word and word not in launch:
                            if len(name) > 6 and len(word) < 3:
                                continue

                            launch[word] = path
    # lists = {
    #     "self.running": running,
    #     "self.launch": launch,
    # }

    # batch update lists
    # print(str(running))
    ctx.lists["user.running"] = running
    ctx.lists["user.launch"] = launch
예제 #30
0
def switch_app(m=None, name=None):
    if name is None:
        name = str(m["switcher.running"][0])

    print(running)
    full = running.get(name)
    if not full:
        return
    for app in ui.apps():
        if app.name == full:
            app.focus()
            # TODO: replace sleep with a check to see when it is in foreground
            time.sleep(0.25)
            break