wechat-personal-message
БесплатноЗапускает вложенные скриптыНе проверен微信自动化助手 — 激活微信 → 置顶窗口 → 搜索联系人 → Vision OCR识别 → 进入聊天 → 自动发送。全程本地运行,支持 OCR 视觉反馈校验,可被外部工具调用。
от aAAaqwq★ 123 звезды на GitHubОб этом скилле
微信自动化助手 (WeChat Automator) v4.2
功能概述
一套完整的微信自动化工具,基于 macOS 原生能力实现,全程本地运行:
激活微信 → 前置置顶窗口 → 搜索联系人 → 截图聊天窗口 → Vision OCR识别 → 关键词匹配 → 自动回复 → 发送消息
依赖与环境
| 依赖 | 要求 | 安装命令 |
|---|---|---|
| macOS | 10.15+ | — |
| pyobjc | 必须 | pip3 install pyobjc |
| cliclick | 必须 | brew install cliclick |
| Vision Framework | 内置 | macOS 10.15+ 自带 |
| screencapture | 内置 | macOS 系统自带 |
权限要求
请按以下步骤开启权限:
- 辅助功能权限:
系统设置 → 隐私与安全性 → 辅助功能 → 终端 → 开启 - 屏幕录制权限:
系统设置 → 隐私与安全性 → 屏幕录制 → 终端 → 开启
快速开始
检查系统环境
python3 ~/.hermes/skills/openclaw-imports/wechat-personal-message/scripts/wechat_automator.py check
完整自动化流程(OCR + 自动回复)
python3 ~/.hermes/skills/openclaw-imports/wechat-personal-message/scripts/wechat_automator.py run -c 张三
仅发送消息(不 OCR)
python3 ~/.hermes/skills/openclaw-imports/wechat-personal-message/scripts/wechat_automator.py send -c 张三 -m "晚上8点开会"
核心函数(供外部调用)
execute_wechat_automation()
主执行函数,支持完整自动化流程。
参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
contact_name |
str | ✅ | 联系人名称(备注名或微信号) |
keyword_dict |
dict | ❌ | 关键词字典,格式 {"类别": ["关键词1", "关键词2"]} |
default_reply |
str | ❌ | 默认回复文案 |
custom_replies |
dict | ❌ | 自定义回复覆盖,格式 {"类别": "回复内容"} |
chat_region |
tuple | ❌ | 截图区域 (x, y, w, h) |
auto_reply |
bool | ❌ | 是否自动回复,默认 True |
verbose |
bool | ❌ | 是否输出详细日志,默认 True |
返回值: 执行结果字典
示例:
from wechat_automator import execute_wechat_automation
result = execute_wechat_automation(
contact_name="张三",
keyword_dict={
"价格": ["多少钱", "价格", "报价"],
"合作": ["合作", "代理", "加盟"],
"问候": ["你好", "您好", "在吗"]
},
default_reply="感谢您的消息,我会尽快回复您。"
)
print(result["success"]) # True/False
print(result["matched_category"]) # 匹配到的类别
print(result["recognized_texts"]) # OCR 识别的文本列表
print(result["reply_content"]) # 发送的回复内容
send_text_message()
快捷函数:仅发送文本消息(不 OCR)。
from wechat_automator import send_text_message
success = send_text_message("张三", "晚上8点开会")
check_system_ready()
检查系统环境是否就绪。
from wechat_automator import check_system_ready
status = check_system_ready()
print(status["ready"]) # True/False
技术实现细节
AppleScript 键盘操作(关键实现)
⚠️ 重要:macOS AppleScript 的特殊键必须用 key code 方式,不能用 keystroke "return":
# ✅ 正确方式:key code
key_code_map = {
"return": 36, # 回车
"enter": 36, # 回车(同 return)
"escape": 53, # ESC
"tab": 48, # Tab
"space": 49, # 空格
"backspace": 51, # 退格
"up": 126, # 上箭头
"down": 125, # 下箭头
"left": 123, # 左箭头
"right": 124, # 右箭头
}
script = '''
tell application "System Events"
key code 36 -- return
end tell
'''
动态窗口坐标计算(关键!)
⚠️ 绝对禁止硬编码坐标。微信窗口位置不固定,必须先获取窗口实际 rect,再按比例计算输入框坐标:
# 1. 获取微信窗口 rect: (x, y, width, height)
script = '''
tell application "System Events"
tell process "WeChat"
get {position, size} of window 1
end tell
end tell
'''
# 返回格式: {{0, 22}, {1514, 1006}} → (x=0, y=22, w=1514, h=1006)
# 2. 按窗口比例计算输入框位置(约窗口右下区域)
input_x = win_x + int(win_w * 0.75) # x方向约75%处
input_y = win_y + int(win_h * 0.92) # y方向约92%处
# 3. 用 process 块内 click 执行点击
script = f'''
tell application "System Events"
tell process "WeChat"
click at {{{input_x}, {input_y}}}
end tell
end tell
'''
OCR 识别(Vision Framework)⚠️ pyobjc API 注意事项
新版 pyobjc (3.x+) API 与旧版不同,以下是已验证可用的 API:
from Vision import VNRecognizeTextRequest, VNImageRequestHandler
from AppKit import NSImage
# 1. 加载图片(必须用 alloc().initWithContentsOfFile_)
img = NSImage.alloc().initWithContentsOfFile_(image_path)
# 2. 创建识别请求并设置回调(不能用 setCompletionHandler_)
recognized_texts = []
def completionHandler(request, error):
if error:
return
for observation in request.results() or []:
text = observation.text()
if text and text.strip():
recognized_texts.append(text)
request = VNRecognizeTextRequest.alloc().initWithCompletionHandler_(completionHandler)
request.setRecognitionLanguages_(["zh-Hans", "en-US"])
request.setUsesLanguageCorrection_(True)
# 3. 执行识别
img_data = img.TIFFRepresentation()
handler = VNImageRequestHandler.alloc().initWithData_options_(img_data, {})
handler.performRequests_error_([request], None)
常见错误:
initWithData_→ 应为initWithData_options_initWithContentsOfFile_()→ 应先用alloc()再调用setCompletionHandler_()→ 应在initWithCompletionHandler_时传入回调initWithImage_options_→ 不存在,必须用initWithData_options_
截图(screencapture)
# 截取指定区域
screencapture -x -R "x,y,width,height" output.png
执行流程详解
1. send_text_message(contact, message)
├─ 保存原始剪贴板(最开始保存,避免被 search_contact 污染)
├─ activate_wechat()
├─ bring_to_front()
├─ search_contact(name) ← 会写入联系人名到剪贴板
├─ send_message(message, original_clipboard) ← 用保存的原始值
└─ 恢复原始剪贴板
2. se
Установить wechat-personal-message в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл wechat-personal-message?
微信自动化助手 — 激活微信 → 置顶窗口 → 搜索联系人 → Vision OCR识别 → 进入聊天 → 自动发送。全程本地运行,支持 OCR 视觉反馈校验,可被外部工具调用。
Как установить скилл wechat-personal-message?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл wechat-personal-message запускает скрипты?
Да, скилл несёт исполняемые скрипты. Проверь исходник перед установкой.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic