コード例 #1
0
def jump_to_target(target):
    press("cmd-left", wait=2000)
    press("cmd-shift-right", wait=2000)
    press("cmd-c", wait=2000)
    press("left", wait=2000)
    line = clip.get()
    print("LINE")
    print(line)
    result = line.find(target)
    if result == -1:
        return
    for i in range(0, result):
        press("right", wait=0)
    for i in range(0, len(target)):
        press("shift-right")
    press("right", wait=0)
コード例 #2
0
def grab_identifier(m):
    old_clip = clip.get()
    # noinspection PyProtectedMember
    times = utils.text_to_number(m._words[1:])  # hardcoded prefix length?
    if not times:
        times = 1
    try:
        old_line, old_col = get_idea_location()
        delayed_click(m, button=0, times=2)
        for _ in range(times - 1):
            send_idea_command("action EditorSelectWord")
        send_idea_command("action EditorCopy")
        send_idea_command("goto {} {}".format(old_line, old_col))
        send_idea_command("action EditorPaste")
    finally:
        clip.set(old_clip)
コード例 #3
0
def add_named_folder(m):
    x = copy_path_to_clipboard(None)
    path = clip.get()
    # Stop if it isn't a folder
    if path[-1] != '/':
        return
    filename = path.split('/')[-2]
    keyword = filename.split(' ')[0]

    with FileInput(files=[folders_filename], inplace=True) as f:
        for line in f:
            line = line.rstrip()
            if line in '{}' or line[-1] is ',':
                print(line)
            else:
                print(line + ',')
                print('    "' + keyword + '": "' + path + '"')
コード例 #4
0
def word_neck(word_index, valid_characters=alphanumeric):
    with clip.revert():
        stop_selection("right")

        actions.edit.extend_line_end()
        time.sleep(0.25)
        actions.edit.copy()
        actions.edit.left()
        time.sleep(0.25)
        text_right = clip.get().lower()

    print(text_right)
    print(word_index, type(word_index))

    is_word = [character in valid_characters for character in text_right]
    word_count = 1
    i = 0
    while i < (len(is_word) - 1) and not is_word[i]:
        i += 1

    # print("a start", i)

    while i < (len(is_word) - 1) and word_count < word_index:
        # print(i, is_word[i], word_count, word_index)
        if not is_word[i] and is_word[i + 1]:
            word_count += 1
        i += 1
    # warning: this is a hack, sorry
    # print("i", i)
    if i == 1 and is_word[0]:
        i = 0
    start_position = i
    # print(text_right[start_position:])
    while i < len(is_word) and is_word[i]:
        i += 1
    end_position = i

    # print(start_position, end_position)
    # cursor over to the found word
    for i in range(0, start_position):
        actions.edit.right()
    # now select the word
    for i in range(0, end_position - start_position):
        actions.edit.extend_right()
コード例 #5
0
def youtube_download(video=True):
    press('escape')
    press('cmd-l')
    press('cmd-c')
    time.sleep(0.1)
    url = clip.get()
    print(f'url: {url}')
    press('escape')

    command = f'youtube-dl '
    if not video:
        command += '--extract-audio '
    command += '{url}'
    print(f'command: {command}')

    return applescript.run(f"""
        tell application "Terminal"
            do script "cd /Users/zdwiel/Music; {command}; exit"
        end tell
        """)
コード例 #6
0
def youtube_download(video=True):
    press("escape")
    press("cmd-l")
    press("cmd-c")
    time.sleep(0.1)
    url = clip.get()
    print(f"url: {url}")
    press("escape")

    command = f"youtube-dl "
    if not video:
        command += "--extract-audio "
    command += "{url}"
    print(f"command: {command}")

    return applescript.run(f"""
        tell application "Terminal"
            do script "cd {os.path.expanduser(DOWNLOAD_PATH)}; {command}; exit"
        end tell
        """)
コード例 #7
0
def word_prev(word_index, valid_characters=alphanumeric):
    with clip.revert():
        stop_selection("left")

        actions.edit.extend_line_start()
        time.sleep(0.25)
        actions.edit.copy()
        actions.edit.right()
        time.sleep(0.25)
        text_right = clip.get().lower()

    text_right = list(reversed(text_right))

    is_word = [character in valid_characters for character in text_right]
    word_count = 1
    i = 0
    while i < (len(is_word) - 1) and not is_word[i]:
        i += 1

    while i < (len(is_word) - 1) and word_count < word_index:
        # print(i, is_word[i], word_count, word_index)
        if not is_word[i] and is_word[i + 1]:
            word_count += 1
        i += 1
    start_position = i
    # print(text_right[start_position:])
    while i < len(is_word) and is_word[i]:
        i += 1
    end_position = i

    # print(start_position, end_position, text_right[start_position:end_position])
    # cursor over to the found word
    for i in range(0, start_position):
        actions.edit.left()
    # now select the word
    for i in range(0, end_position - start_position):
        actions.edit.extend_left()
コード例 #8
0
ファイル: utils.py プロジェクト: ym-han/talon_starter_pack
 def wrapped_function(*args, **kwargs):
     old = clip.get()
     ret = fn(*args, **kwargs)
     sleep(0.1)
     clip.set(old)
     return ret
コード例 #9
0
def copy_selected():
    press("cmd-c")
    sleep(0.25)
    return clip.get()
コード例 #10
0
 def homophones_force_show_selection():
     """Sentence formatter"""
     actions.edit.copy()
     actions.sleep("100ms")
     raise_homophones(clip.get(), True, True)
コード例 #11
0
 def __enter__(self):
     self.old_clipboard = clip.get()
コード例 #12
0
ファイル: __init__.py プロジェクト: jcaw/talon_config
def clip_set_safe(new_value, timeout=2):
    """Set clipboard to `new_value`"""
    if clip.get() == new_value:
        return
    with WaitForClipChange(timeout):
        clip.set_text(new_value)
コード例 #13
0
 def paste_match_style():
     clip.set_text(clip.get())
     time.sleep(0.1)
     actions.paste()
コード例 #14
0
def send_clip_to_register(m):
    press("ctrl-c")
    cur_reg = int(m._words[-1])
    regs_list[cur_reg] = clip.get()
コード例 #15
0
ファイル: __init__.py プロジェクト: jcaw/talon_config
 def __enter__(self):
     self.original_clip = clip.get()
     self.end_time = time.monotonic() + self.timeout
コード例 #16
0
 def selected_text():
     # gv to reselect
     actions.insert("ygv")
     return clip.get()
コード例 #17
0
 def get_clip() -> str:
     """returns the clipboard content"""
     return clip.get()
コード例 #18
0
ファイル: numbers.py プロジェクト: fidgetingbits/knausj_talon
 def convert_hex_dump_pointer():
     """convert a number string to hex value"""
     b = clip.get().strip().split(" ")
     actions.insert("0x" + "".join(b[::-1]))
コード例 #19
0
 def wrapped_function(*args, **kwargs):
     old = clip.get()
     fn(*args, **kwargs)
     clip.set(old)
コード例 #20
0
 def selected_text():
     with PreserveClipboard():
         edit.copy()
         time.sleep(0.1)
         return clip.get()
コード例 #21
0
ファイル: __init__.py プロジェクト: jcaw/talon_config
 def __exit__(self, *_):
     while clip.get() == self.original_clip:
         if time.monotonic() > self.end_time:
             raise TimeoutError("Clipboard did not change before timeout.")
         else:
             time.sleep(0.01)