You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MacOS下如何用单条命令实现打开网页并自动输入验证代码?

在macOS下用单条命令打开网页并自动输入验证码

实现思路

单纯的open命令只能完成打开网页的操作,无法自动输入内容,需要结合AppleScript模拟系统键盘输入,将两步整合为一条命令。

具体命令

将以下命令中的你的验证码内容替换为实际验证代码,按需调整延迟时间:

osascript -e 'tell application "Google Chrome" to open location "https://assessments.cem.org/incas/GetSessionID.aspx?regkey=378BDA36-F094-4XXXXXXXXXXXXXXX"' -e 'delay 5' -e 'tell application "System Events" to keystroke "你的验证码内容"'

细节说明

  • -e 参数用于执行多条AppleScript语句,依次完成打开网页、等待加载、输入验证码的操作
  • delay 5 是等待页面加载的时间,可根据网页实际加载速度调整为3-10秒
  • 如果验证码输入框未自动获得焦点,可在输入前添加Tab切换焦点的步骤,修改后的命令示例:
    osascript -e 'tell application "Google Chrome" to open location "https://assessments.cem.org/incas/GetSessionID.aspx?regkey=378BDA36-F094-4XXXXXXXXXXXXXXX"' -e 'delay 5' -e 'tell application "System Events" to keystroke tab' -e 'delay 0.5' -e 'tell application "System Events" to keystroke "你的验证码内容"'
    
  • 权限配置:需要在「系统设置-隐私与安全性-辅助功能」中,将你使用的命令行工具(如终端)添加到权限列表,否则无法模拟键盘操作
  • 适用限制:此方法仅适用于固定验证码的场景,若验证码每次随机生成则无法用此方式自动输入

内容的提问来源于stack exchange,提问作者Nicolas Liu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 14:40:29