{"id":48600055,"url":"https://github.com/yunkai/macos-wechat-sender","last_synced_at":"2026-05-02T02:00:47.665Z","repository":{"id":348067033,"uuid":"1196356135","full_name":"yunkai/macos-wechat-sender","owner":"yunkai","description":null,"archived":false,"fork":false,"pushed_at":"2026-04-25T22:32:28.000Z","size":154,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-26T00:33:26.062Z","etag":null,"topics":["automation","macos","openclaw-skill","wechat"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yunkai.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-03-30T16:09:32.000Z","updated_at":"2026-04-25T22:32:33.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/yunkai/macos-wechat-sender","commit_stats":null,"previous_names":["yunkai/macos-wechat-sender"],"tags_count":18,"template":false,"template_full_name":null,"purl":"pkg:github/yunkai/macos-wechat-sender","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yunkai%2Fmacos-wechat-sender","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yunkai%2Fmacos-wechat-sender/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yunkai%2Fmacos-wechat-sender/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yunkai%2Fmacos-wechat-sender/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yunkai","download_url":"https://codeload.github.com/yunkai/macos-wechat-sender/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yunkai%2Fmacos-wechat-sender/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32520156,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-02T01:12:54.858Z","status":"online","status_checked_at":"2026-05-02T02:00:05.923Z","response_time":132,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automation","macos","openclaw-skill","wechat"],"created_at":"2026-04-08T21:33:07.325Z","updated_at":"2026-05-02T02:00:47.657Z","avatar_url":"https://github.com/yunkai.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# macos-wechat-sender\n\n在 Mac 上通过 Python 自动化发送微信消息的工具。\n\n## 功能\n\n- ✅ 支持给任意微信联系人发送消息\n- ✅ 支持中文消息\n- ✅ 支持文件发送\n- ✅ 支持公众号文章卡片转发（RapidOCR 自动化）\n- ✅ 跨平台支持（仅限 macOS）\n- ✅ 简单易用的 API\n\n## 前置要求\n\n- macOS 操作系统\n- 已安装并登录微信桌面客户端\n- Python 3.7+\n- ⚠️ **必须关闭 macOS 微信通知权限**（系统设置 → 通知 → 微信 → 关闭）\n  - 原因：微信通知弹窗会遮挡 UI 元素，导致自动化脚本点击位置偏移或点击到错误的按钮\n  - 此为用户手动配置（2026-03-31）\n\n## 安装\n\n### 1. 克隆项目\n\n```bash\ngit clone https://github.com/yunkai/macos-wechat-sender.git\ncd macos-wechat-sender\n```\n\n### 2. 安装依赖\n\n```bash\npip3 install pyautogui pyperclip rapidocr numpy pillow\n```\n\n## 使用方法\n\n### 命令行使用\n\n```bash\npython3 scripts/send_wechat.py \u003c联系人\u003e \u003c消息\u003e\n\n# 示例\npython3 scripts/send_wechat.py 文件传输助手 你好\npython3 scripts/send_wechat.py 小明 -f /path/to/file.pdf\n```\n\n🚨 **重要提醒**：使用前请确保「联系人」的名称完全正确，否则可能会发送给错误的对象！\n\n### 作为模块导入\n\n```python\nfrom scripts.send_wechat import clean_window, search_and_select, send_message\n\n# 清洁窗口（每次发送前必须执行）\nclean_window()\n\n# 搜索并选中联系人\nsearch_and_select(\"联系人名称\")\n\n# 发送消息\nsend_message(\"消息内容\")\n```\n\n## 工作原理\n\n1. **clean_window()** - 打开微信窗口，先按 Escape 关闭浮窗，再关闭所有子窗口，确保窗口状态干净\n2. **search_and_select(target_name)** - Cmd+F 打开搜索框，粘贴并搜索联系人名称，Enter 打开聊天\n3. **send_message(msg)** - 粘贴消息内容，Enter 发送文本消息\n4. **send_file(file_path)** - osascript 复制文件到剪贴板，Cmd+V 粘贴，Enter 发送文件\n5. **forward_article_via_browser(url, target)** - 发送链接到跳板联系人 → RapidOCR 定位 URL 单击打开文章 → 转发菜单 → 搜索目标联系人 → 发送按钮，文章以卡片形式发出\n\n## 公众号文章卡片转发\n\n使用 `-l` / `--url` 参数，可将公众号文章以**卡片形式**转发给指定联系人：\n\n```bash\npython3 scripts/send_wechat.py 家人群 -l \"https://mp.weixin.qq.com/s/xxx\"\n```\n\n### 转发+引用消息\n\n使用 `-l` 和 `-q` 参数组合，可将文章卡片转发后，引用该卡片发送文本消息：\n\n```bash\npython3 scripts/send_wechat.py 老王 -l \"https://mp.weixin.qq.com/s/xxx\" -q \"这篇文章写得很好，推荐看看\"\n```\n\n这会：\n1. 将文章卡片转发给目标联系人\n2. 在目标聊天窗口找到卡片\n3. 右键选择「引用」\n4. 在引用输入框中发送指定文本\n\n## 关键技术点\n\n| 技术 | 说明 |\n|------|------|\n| `pyautogui` | 模拟键盘鼠标操作 |\n| `pyperclip` | 解决中文输入问题 |\n| `osascript` | 精确关闭微信窗口、复制文件到剪贴板 |\n| `subprocess` | 启动和管理应用 |\n\n### 文件发送原理\n\n文件发送的核心是使用 osascript 将文件复制到剪贴板：\n\n```python\nscript = f'set the clipboard to (POSIX file \"{abs_file_path}\")'\nsubprocess.run(['osascript', '-e', script])\n```\n\n然后在微信聊天框中 Cmd+V 粘贴，文件就会作为微信文件消息发送。\n\n## 常见问题\n\n### Q: 消息发空了怎么办？\nA: 检查 `send_message()` 中的 `pyperclip.copy()` 后是否等了足够的 `time.sleep(0.2)`。\n\n### Q: 搜索词粘贴到了消息框怎么办？\nA: `search_and_select()` 开始时会按 Escape 确保不在输入模式。\n\n### Q: 消息发错了联系人怎么办？\nA: 每次发送前请确保执行了 `clean_window()`。\n\n### Q: 如何发送文件？\nA: 使用 `-f` 选项：`python3 scripts/send_wechat.py 小明 -f /path/to/file.pdf`\n\n## 版本历史\n\n- **v1.15.0** - forward_article_with_quote step 4/4 修复：动态检测菜单弹出窗口（宽\u003c400高\u003c500），全屏截图后裁剪菜单区域再OCR，避免全屏误匹配；移除fallback，找不到引用直接报错退出；支持任意微信窗口尺寸\n- **v1.14.0** - 修复浏览器窗口检测时机问题：单击链接代替双击，删除多余激活步骤\n- **v1.13.0** - 卡片检测算法支持白天/夜间模式自动切换\n- **v1.12.0** - 卡片检测算法重构：peekaboo frontmost 截图 + 右侧区域过滤 + 选择最下面卡片，窗口大小通用\n- **v1.7.0** - 修复 RapidOCR URL 匹配逻辑（http/https 开头精确匹配）\n- **v1.5.0** - 新增公众号文章卡片转发功能（RapidOCR URL 识别 + 转发浮窗自动化）\n- **v1.2.0** - 初始版本，支持文本消息发送\n\n## 项目结构\n\n```\nmacos-wechat-sender/\n  - README.md             (本文件)\n  - SKILL.md              (OpenClaw 技能说明)\n  - scripts/\n      send_wechat.py     (发送脚本)\n      test_send_wechat.py (回归测试)\n  - tests/\n      test.pdf            (测试用PDF文件)\n```\n\n## 在 OpenClaw 等 Agent 中使用\n\n此项目可以作为 OpenClaw 或其他 AI Agent 的 Skill 来使用。\n\n### 方法一：放入 OpenClaw Skills 目录\n\n```bash\n# 复制到 OpenClaw 工作空间\ncp -r macos-wechat-sender ~/.openclaw/workspace/skills/\n\n# 或者创建软链接\nln -s $(pwd)/macos-wechat-sender ~/.openclaw/workspace/skills/macos-wechat-sender\n```\n\n### 方法二：触发关键词\n\n当对 OpenClaw 说以下内容时，会触发此技能：\n\n- \"发送微信消息\"\n- \"给 XXX 发微信消息\"\n- \"给 XXX 发文件\"\n- \"微信自动发送\"\n- \"通过 Python 发送微信消息\" \"\n\n### 方法三：直接调用脚本\n\n```bash\npython3 scripts/send_wechat.py \u003c联系人\u003e \u003c消息\u003e\n```\n\n### 方法四：给 AI 一个提示词让它安装\n\n直接把以下提示词发给 AI：\n\n```\n请安装 macos-wechat-sender 这个 Skill：\n- 项目地址：https://github.com/yunkai/macos-wechat-sender\n- 功能：在 Mac 上自动化发送微信消息\n- 安装步骤：\n  1. git clone https://github.com/yunkai/macos-wechat-sender.git\n  2. cd macos-wechat-sender\n  3. pip3 install pyautogui pyperclip rapidocr onnxruntime\n  4. 复制到 ~/.openclaw/workspace/skills/macos-wechat-sender\n```\n\n### OpenClaw Skill 配置示例 (SKILL.md)\n\nSKILL.md 已包含完整的技能说明，OpenClaw 会自动识别。\n\n## License\n\nMIT License\n\n## 作者\n\n- **Yunkai** - [GitHub](https://github.com/yunkai)\n- **OpenClaw**\n- **MiniMax-M2.7-highspeed**\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyunkai%2Fmacos-wechat-sender","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyunkai%2Fmacos-wechat-sender","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyunkai%2Fmacos-wechat-sender/lists"}