WeChat Send
Send messages to WeChat contacts by automating the macOS WeChat desktop app.
Prerequisites
- - WeChat for Mac installed and logged in
- macOS Accessibility permission granted to
node (System Settings → Privacy & Security → Accessibility) - WeChat window must be open (not minimized to dock)
Usage
Run the script:
CODEBLOCK0
Examples
CODEBLOCK1
How It Works
- 1. Activates WeChat and opens search (Cmd+F)
- Types the contact name, selects the first result (Enter), closes search (Escape)
- Clicks the message input field using JXA CGEvent mouse simulation
- Pastes the message from clipboard (Cmd+V) and sends (Enter)
Limitations
- - Contact name must exactly match a WeChat contact (first search result is selected)
- Cannot send images or files (text only)
- Cannot read incoming messages
- WeChat window position affects click coordinates (auto-calculated from window bounds)
- If the contact search returns wrong results, the message goes to the wrong person — use specific names
- Only one message at a time; for multiple recipients, call the script multiple times
Troubleshooting
- - Message not sent: Ensure WeChat window is visible (not minimized) and the correct contact was found
- Accessibility error: Re-grant node permission in System Settings → Accessibility, then restart the gateway
- Wrong contact: Use a more specific name to avoid ambiguous search results
微信发送
通过自动化macOS微信桌面应用向微信联系人发送消息。
前置条件
- - 已安装Mac版微信并登录
- 已授予node macOS辅助功能权限(系统设置 → 隐私与安全性 → 辅助功能)
- 微信窗口必须打开(未最小化到程序坞)
使用方法
运行脚本:
bash
bash scripts/wechat_send.sh <联系人名称> <消息内容>
示例
bash
发送简单消息
bash scripts/wechat_send.sh Ryan 你好!
发送较长消息
bash scripts/wechat_send.sh Ellison 明天下午3点开会,别忘了带文件
工作原理
- 1. 激活微信并打开搜索(Cmd+F)
- 输入联系人名称,选择第一个结果(回车),关闭搜索(Escape)
- 使用JXA CGEvent鼠标模拟点击消息输入框
- 从剪贴板粘贴消息(Cmd+V)并发送(回车)
局限性
- - 联系人名称必须完全匹配微信联系人(选择第一个搜索结果)
- 无法发送图片或文件(仅支持文本)
- 无法读取收到的消息
- 微信窗口位置影响点击坐标(根据窗口边界自动计算)
- 如果联系人搜索返回错误结果,消息会发送给错误对象——请使用具体名称
- 每次只能发送一条消息;如需发送给多个收件人,请多次调用脚本
故障排除
- - 消息未发送:确保微信窗口可见(未最小化)且找到了正确的联系人
- 辅助功能错误:在系统设置 → 辅助功能中重新授予node权限,然后重启网关
- 联系人错误:使用更具体的名称以避免搜索结果歧义