-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
clippy.py
110 lines (86 loc) · 3.24 KB
/
clippy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
from typing import Any, Optional
from talon import Module, Context, actions, app, ui
from ...core.rpc_client.rpc_client import RpcClient
from .clippy_targets import ClippyPrimitiveTarget, ClippyTarget
key = "cmd-shift-f18" if app.platform == "mac" else "ctrl-shift-alt-o"
rpc = RpcClient("Clippy", key)
mod = Module()
mod.list("clippy_command_with_targets", desc="Clippy commands WITH targets")
mod.list("clippy_command_no_targets", desc="Clippy commands WITHOUT targets")
mod.tag(
"clippy_showing", desc="Tag is active whenever clippy window is showing/not hidden"
)
mod.apps.clippy = r"""
app.name: Electron
title: /Clippy/
"""
ctx = Context()
ctx.lists["user.clippy_command_with_targets"] = {
"paste": "pasteItems",
"chuck": "removeItems",
"copy": "copyItems",
}
ctx.lists["user.clippy_command_no_targets"] = {
# "exit": "exit",
"toggle": "toggleShowHide",
"show": "show",
"hide": "hide",
"pin toggle": "togglePinned",
"pin": "pin",
"unpin": "unpin",
"dev tools": "toggleDevTools",
"dev tools show": "showDevTools",
"dev tools hide": "hideDevTools",
"search": "toggleSearch",
"search show": "showSearch",
"search hide": "hideSearch",
"pause toggle": "togglePaused+",
"pause": "pause",
"resume": "resume",
"auto star": "toggleAutoStar",
"auto star on": "enableAutoStar",
"auto star off": "disableAutoStar",
# "clear": "removeAllItems",
# "remove list": "removeList",
}
@mod.action_class
class Actions:
def clippy_command_no_targets(command_id: str):
"""Send command without targets to the clipboard manager"""
send({"id": command_id})
def clippy_command_with_targets(command_id: str, targets: list[ClippyTarget]):
"""Send a command with targets to the clipboard manager"""
if command_id == "pasteItems":
command = {"id": "copyItems", "targets": targets}
send(command)
actions.sleep("50ms")
actions.edit.paste()
else:
send({"id": command_id, "targets": targets})
def clippy_paste_indices(indices: list[int]):
"""Paste items from the clipboard manager at the given indices"""
targets = [ClippyPrimitiveTarget(str(i)) for i in indices]
actions.user.clippy_command_with_targets("pasteItems", targets)
def clippy_search(text: str):
"""Search for <text> in the clipboard manager"""
send({"id": "search", "text": text})
def clippy_rename(targets: list[ClippyTarget], text: Optional[str] = None):
"""Rename clipboard targets to <text>"""
send({"id": "renameItems", "targets": targets, "text": text})
def clippy_get(targets: list[ClippyTarget]):
"""Get clipboard targets"""
result = get({"id": "getItems", "targets": targets})
print(result)
def send(command: Any):
rpc.send(command, wait_for_finish=True)
def get(command: Any):
return rpc.send(command, return_command_output=True)
def update(window, onShow):
if window.title != "Clippy" or window.app.name != "Clippy":
return
if onShow:
ctx.tags = ["user.clippy_showing"]
else:
ctx.tags = []
ui.register("win_show", lambda win: update(win, True))
ui.register("win_hide", lambda win: update(win, False))