JiFu's Wiki JiFu's Wiki
首页
  • HTML
  • JavaScript
  • NodeJS
  • Vuejs
  • 微信小程序
  • Python
  • 数据库
  • 中间件
  • 算法
  • 软件工程
  • Wordpress
  • iOS开发
  • Android开发
  • Linux
  • Windows
  • MacOS
  • Docker
  • Vim
  • VSCode
  • Office
  • 其他
  • Photoshop
  • Sketch
  • Mac
  • 游戏
关于
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
首页
  • HTML
  • JavaScript
  • NodeJS
  • Vuejs
  • 微信小程序
  • Python
  • 数据库
  • 中间件
  • 算法
  • 软件工程
  • Wordpress
  • iOS开发
  • Android开发
  • Linux
  • Windows
  • MacOS
  • Docker
  • Vim
  • VSCode
  • Office
  • 其他
  • Photoshop
  • Sketch
  • Mac
  • 游戏
关于
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • DevOps介绍
  • Linux

  • MacOS

    • MacOS介绍
    • MacOS 如何提高 PDF 的对比度?
    • Charles从入门到精通
    • Compiling PyQt5 for Python 2.7 on MacOS
    • Homebrew让你从Mac切换到Linux更轻松
    • Mac OS X设置SMB进行文件共享
    • Mac OS系统加速:干掉那些「炫酷」的动画
    • Mac 时间机器 Time Machine 备份速度太慢的解决方法 (加速备份命令)
    • macOS 下 FFmpeg 视频转码入门及进阶使用心得
    • Mac定时任务-利用launchctl定时启动任务
    • Mac的最大连接数限制和端口的相关参数的设置
    • Mac重置系统管理控制器SMC
    • Mac高效使用技巧
    • MacOS一个惊人快速的终端录像工具
    • 一览Mac OS 图形界面的发展史
    • 修复Mac破解应用开打时闪退
    • 在M1芯片Mac上使用Homebrew
    • 如何查看 macOS 系统日志
    • 如何重置Mac上的NVRAM
    • 强制退出Mac程序的六种方法
    • 苹果 Mac 重置 SMC、NVRAM、PRAM 方法教程 - 解决 macOS 卡顿或无法启动
    • 苹果M1芯片Macbook安装win10
    • 解决“Mac应用”已损坏,无法打开的问题
    • 解决Mac修改DNS卡死-命令行修改Mac OS系统DNS设置
    • MacOS Photoshop屏蔽正版验证
    • 26.Karabiner自定义组合快捷键
      • Ctrl + Delete -> Option + Delete
      • Fn + double K -> 修改karabiner profile
      • 双击left control -> 右侧shift (用于快速切换输入法, 需要提前修改搜狗输入法的快捷键)
      • Option + Arrow Up -> Page Up
      • 复制粘贴堆栈( command + c 复制并入栈 / command + v 复制 / command + shift + v 内容出栈 )
    • MacOS软件推荐
    • Disable notification "to get future google chrome updates you'll need macos 10.13 or later" on mac
  • Windows

  • Docker

  • Vim

  • VSCode

  • Office

  • 其他

  • 运维
  • MacOS
JiFu
2025-02-03
目录

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

# 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

# 双击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

# 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

# 复制粘贴堆栈( 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
#!/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
#Karabiner-Elements
上次更新: 2025/02/05, 07:44:40
MacOS Photoshop屏蔽正版验证
MacOS软件推荐

← MacOS Photoshop屏蔽正版验证 MacOS软件推荐→

最近更新
01
WPS快捷键
05-21
02
Disable notification "to get future google chrome updates you'll need macos 10.13 or later" on mac
05-14
03
MacOS软件推荐
04-30
更多文章>
Theme by Vdoing | Copyright © 2019-2025 Ji Fu | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式