{"id":13600093,"url":"https://github.com/x5iu/wemac","last_synced_at":"2026-01-27T03:43:18.120Z","repository":{"id":229010536,"uuid":"775249610","full_name":"x5iu/wemac","owner":"x5iu","description":"一个 it just works 的 Mac 版微信 RPA 群聊机器人","archived":false,"fork":false,"pushed_at":"2025-12-23T15:58:32.000Z","size":21,"stargazers_count":196,"open_issues_count":0,"forks_count":22,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-12-25T05:41:39.307Z","etag":null,"topics":["chatbot","rpa","wechat"],"latest_commit_sha":null,"homepage":"","language":"AppleScript","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/x5iu.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}},"created_at":"2024-03-21T03:01:18.000Z","updated_at":"2025-12-25T01:41:58.000Z","dependencies_parsed_at":"2024-05-01T21:16:16.596Z","dependency_job_id":"d4ae69af-83c9-4199-9b38-013f24cc52ed","html_url":"https://github.com/x5iu/wemac","commit_stats":null,"previous_names":["x5iu/wemac"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/x5iu/wemac","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/x5iu%2Fwemac","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/x5iu%2Fwemac/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/x5iu%2Fwemac/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/x5iu%2Fwemac/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/x5iu","download_url":"https://codeload.github.com/x5iu/wemac/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/x5iu%2Fwemac/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28800354,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-27T03:37:11.304Z","status":"ssl_error","status_checked_at":"2026-01-27T03:37:10.427Z","response_time":168,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["chatbot","rpa","wechat"],"created_at":"2024-08-01T18:00:25.821Z","updated_at":"2026-01-27T03:43:18.108Z","avatar_url":"https://github.com/x5iu.png","language":"AppleScript","funding_links":[],"categories":["AppleScript","Kimi CLI Related Projects"],"sub_categories":["Common Commands"],"readme":"# Mac 版微信 RPA 群聊机器人\n\n这是一个利用 AppleScript 和 Mac 版微信客户端制作的简易版微信机器人。这个机器人起源于我想做一个 ChatBot，帮我记录消费、饮食、运动等数据，以及帮我总结微信公众号文章内容。目前利用个人微信实现 ChatBot 的方案，主流的是 wechaty，但是 wechaty 使用的 puppet 中，免费的网页版或 UOS 版本不够稳定（不稳定的意思是经常莫名奇妙被踢下线），稳定且功能丰富的 ipadloacl 等方案又需要花费额外的金币购买 token。于是我经过一些小小的尝试，实现了这个速度慢、功能少但足够稳定的微信机器人（*选择 Mac 版微信客户端是因为我手上只有 Mac 设备*）。\n\n## 如何跑起来\n\n这个机器人主要利用 AppleScript 完成，辅以一些 Python 代码，使用 Python 是因为 AppleScript 自带的鼠标点击操作无法作用于微信客户端，因此使用了额外的 Python 库来实现点击操作。因此，你需要先有一个 Python3 的解释器，以及安装 [PyUserInput](https://github.com/PyUserInput/PyUserInput)：\n\n```\npip3 install PyUserInput\n```\n\n当然，如果你有其他模拟鼠标点击的方案，也可以用自己的（在写这篇 README 时才发现 PyUserInput 已经 Deprecated 了）。\n\n接下来，你需要修改 `wemac.applescript` 中的一些配置，如下所示：\n\n- **chatWindowName**: 指定当前处理哪一个窗口的聊天，如果是私聊则是对方的昵称或备注，如果是群聊则是群聊名称;\n- **botName**: 机器人本身账号的名称，其作用是判断是否有人 at 自己，然后进行回复;\n- **pythonBin**: Python3 解释器的路径;\n- **workingDir**: 工作目录，也是放置 `mouseclick.py` 文件的目录;\n- **windowOffset**: 基本上，这个值是显示器宽度 - 400 - 20，它的作用是用于定位由机器人发送的消息的位置（如果你发现执行 AppleScript 的过程中，脚本无法顺利删除机器人自己发送的消息，请尝试调整这个值）;\n\n设置完上述变量后，就可以尝试运行一次脚本了，**运行之前，请确保已登录 Mac 版微信**。执行脚本，你会发现 AppleScript 会自动找到目标的聊天，点击聊天窗口，~~并开始删除最近的一条聊天记录~~ **2025-12-23 更新，现在会滚动屏幕到第一条消息处，从第一条消息处开始删除消息**，没错，这个 AppleScript 会删除聊天记录，这是因为没有地方记录每条消息是否已被回复，只能通过删除消息的方式来避免重复回复消息；删除完消息后，如果这条消息 at 了机器人，则会进行回复；然后，AppleScript 的执行就结束了，注意，**一次 AppleScript 执行只会处理一条消息**。\n\n那么如何让机器人一直运作下去呢，可行的方案是写个 `run.sh`，在里面写死循环不断执行 `wemac.applescript`（事实上我自己也是这么做的）。\n\n### 如何自定义回复内容\n\n如果想自定义回复内容，比如接入大语言模型，在 `wemac.applescript` 的 320 行，“消息处理逻辑”注释处，你可以添加自己的回复逻辑，由于 AppleScript 本身能力有限，你可以利用 shell 外接其他语言，例如 Python，你可以用以下方式调用 [Kimi CLI](https://github.com/MoonshotAI/kimi-cli) 来获得 Kimi 的回复：\n\n```\nset replyMessage to do shell script \"kimi --print -c '\" \u0026 (my escaped(question)) \u0026 \"' --output-format stream-json | tail -n1 | jq -r '.content[-1].text'\"\n```\n\n被执行的 shell 的标准输出（stdout）将会赋值给 `replyMessage`，然后作为回复由机器人发出去。\n\n在拼接 shell 命令时，可以使用 `escaped` 函数转义参数，以避免注入攻击。\n\n至此，一个简单的聊天机器人就跑起来了，期间可能遇到一些无法定位元素的错误，但是一般而言忽略他们重新运行一遍 AppleScript 就可以了。\n\n## 局限\n\n- 无法获取用户唯一 ID，openid 和 unionid 都不可以，只有昵称或备注；\n- 无法获取消息的唯一 ID，只能处理一条删一条；\n- 处理速度慢，如果群聊的速度大于 AppleScript 的运行速度，那就会出现消息永远无法被处理的情况；\n- 必须用一台 Mac 来 Host，当然也可以通过开虚拟机的方式让一台 Mac 运行多个机器人；\n- 一个 AppleScript 脚本只能处理一个聊天窗口，当然也可以在 `run.sh` 中同时添加多个 AppleScript 以处理不同的聊天，但这样会拖慢运行速度；\n\n但好处就是足够稳定，只要登录上基本能一直运行下去，而且用 AppleScript 模拟点击理论上也不会被微信检测到异常行为导致封号。\n\n## 其他\n\n使用的 Mac 微信客户端版本是 `Version. 3.8.6 (28078)`。\n\n## TODO\n\n- [ ] 支持处理图片、语音、链接等消息；\n- [ ] 支持发送图片、文件；\n- [ ] 支持发送朋友圈；\n- [ ] **支持企业微信**；\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fx5iu%2Fwemac","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fx5iu%2Fwemac","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fx5iu%2Fwemac/lists"}