26.Karabiner自定义组合快捷键
# 自定义组合键
# Ctrl + Delete -> Option + Delete
修改默认快捷键, 用于快速删除文件
{
"description": "Remap Ctrl + Delete to Option + Delete and Shift + Caps Lock",
"manipulators": [
{
"from": {
"key_code": "delete_or_backspace",
"modifiers": {
"mandatory": ["left_control"],
"optional": ["any"]
}
},
"to": [
{
"key_code": "delete_or_backspace",
"modifiers": ["left_option"]
}
],
"type": "basic"
},
{
"from": {
"key_code": "caps_lock",
"modifiers": {
"mandatory": ["left_shift"],
"optional": ["any"]
}
},
"to": [
{
"key_code": "page_down",
"modifiers": []
}
],
"type": "basic"
},
{
"from": {
"key_code": "caps_lock",
"modifiers": {
"mandatory": ["right_shift"],
"optional": ["any"]
}
},
"to": [
{
"apple_vendor_keyboard_key_code": "mission_control",
"modifiers": ["left_command"]
}
],
"type": "basic"
}
]
}
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
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
# Fn + double K -> 修改karabiner profile
于切换 Karaite profile
{
"description": "Press Fn + double K to enable default profile",
"manipulators": [
{
"from": {
"modifiers": { "mandatory": ["fn"] },
"simultaneous": [
{ "key_code": "k" },
{ "key_code": "k" }
]
},
"to": [{ "shell_command": "'/Library/Application Support/org.pqrs/Karabiner-Elements/bin/karabiner_cli' --select-profile 'maplestory'" }],
"type": "basic"
}
]
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 双击left control -> 右侧shift (用于快速切换输入法, 需要提前修改搜狗输入法的快捷键)
{
"description": "double left shift to cap_lock",
"manipulators": [
{
"conditions": [
{
"name": "left_control pressed",
"type": "variable_if",
"value": 1
}
],
"from": {
"key_code": "left_control",
"modifiers": { "optional": ["any"] }
},
"to": [{ "key_code": "right_shift" }],
"type": "basic"
},
{
"from": {
"key_code": "left_control",
"modifiers": { "optional": ["any"] }
},
"to": [
{
"set_variable": {
"name": "left_control pressed",
"value": 1
}
},
{ "key_code": "left_control" }
],
"to_delayed_action": {
"to_if_canceled": [
{
"set_variable": {
"name": "left_control pressed",
"value": 0
}
}
],
"to_if_invoked": [
{
"set_variable": {
"name": "left_control pressed",
"value": 0
}
}
]
},
"type": "basic"
}
]
}
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
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
# Option + Arrow Up -> Page Up
{
"description": "option + Up to Page Up",
"manipulators": [
{
"from": {
"key_code": "up_arrow",
"modifiers": {
"mandatory": ["option"],
"optional": ["caps_lock", "option"]
}
},
"to": [{ "key_code": "page_up" }],
"type": "basic"
}
]
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 复制粘贴堆栈( command + c 复制并入栈 / command + v 复制 / command + shift + v 内容出栈 )
{
"description": "Clipboard Stack Management (Command + C to copy and push to stack, Command + Shift + V to pop from stack)",
"manipulators": [
{
"from": {
"key_code": "c",
"modifiers": {
"mandatory": ["left_command"],
"optional": ["any"]
}
},
"to": [
{
"key_code": "c",
"modifiers": ["left_command"]
},
{ "shell_command": "~/clipboard_stack.py copy" }
],
"type": "basic"
},
{
"from": {
"key_code": "v",
"modifiers": {
"mandatory": ["command", "shift"],
"optional": ["any"]
}
},
"to": [{ "shell_command": "~/clipboard_stack.py stack_paste" }],
"type": "basic"
},
{
"from": {
"key_code": "z",
"modifiers": {
"mandatory": ["command", "shift"],
"optional": ["any"]
}
},
"to": [{ "shell_command": "~/clipboard_stack.py clear" }],
"type": "basic"
}
]
}
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
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
#!/opt/homebrew/bin/python3.9
# -*- coding: utf-8 -*-
import os
import sys
import uuid
import subprocess
import json
STACK_FILE = os.path.expanduser("~/.clipboard_stack.json")
def play_sound():
""" 播放提示音 """
sound_file = "/System/Library/Sounds/Glass.aiff" # MacOS 自带音效文件
if os.path.exists(sound_file):
subprocess.run(["afplay", sound_file, "-r", "1.5"], check=False)
else:
subprocess.run(["say", "Done"], check=False) # 备用方案,使用 TTS 语音提示
def load_stack():
""" 读取剪贴板堆栈文件,并解析为数组 """
if os.path.exists(STACK_FILE) and os.path.getsize(STACK_FILE) > 0:
with open(STACK_FILE, "r", encoding="utf-8") as file:
try:
return json.load(file)
except json.JSONDecodeError:
return []
return []
def save_stack(stack):
""" 将数组数据写入文件 """
with open(STACK_FILE, "w", encoding="utf-8") as file:
json.dump(stack, file, ensure_ascii=False, indent=4)
def push_to_stack(content):
""" 将内容推入堆栈 """
stack = load_stack()
if any(entry["content"] == content for entry in stack):
print("Duplicate content, skipping push to stack.")
return
stack.append({"id": uuid.uuid4().hex, "content": content})
save_stack(stack)
print("Content pushed to stack.")
def pop_from_stack():
""" 弹出最新的剪贴板内容,并从堆栈中删除 """
stack = load_stack()
if stack:
latest_entry = stack.pop()
save_stack(stack)
return latest_entry["content"]
return None
def show_stack():
""" 显示堆栈内容 """
stack = load_stack()
if stack:
print(f"Total entries: {len(stack)}")
for idx, entry in enumerate(stack, 1):
print("=" * 80)
print(f"{idx}. {entry['content']}")
else:
print("Clipboard stack is empty.")
def clear_stack():
""" 清空堆栈 """
if os.path.exists(STACK_FILE):
os.remove(STACK_FILE)
print("Clipboard stack cleared.")
else:
print("No stack file found to clear.")
def copy_clipboard():
""" 复制当前剪贴板内容并存入堆栈 """
clipboard_content = subprocess.run("pbpaste", capture_output=True, text=True).stdout.strip()
if clipboard_content:
push_to_stack(clipboard_content)
else:
print("Clipboard content is empty, nothing to push.")
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: python clipboard_stack.py <command>")
sys.exit(1)
command = sys.argv[1].lower()
if command == "copy":
copy_clipboard()
elif command == "show":
show_stack()
elif command == "clear":
clear_stack()
elif command == "stack_paste":
content = pop_from_stack()
if content:
subprocess.run(f"echo '{content}' | pbcopy", shell=True)
print(f"Popped from stack and copied to clipboard: {content}")
play_sound()
else:
print("Clipboard stack is empty.")
else:
print(f"Unknown command: {command}. Available commands: copy, show, clear, stack_paste.")
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
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
上次更新: 2025/02/05, 07:44:40