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

如何通过脚本实现列表项自动逐个输入?

修正后的AppleScript实现逐个输入列表项

原代码存在语法和逻辑错误,以下是修正后的可用版本:

set theList to {"Apple Watch", "iMac", "iPhone", "MacBook Pro"}

tell application "System Events"
    -- 遍历列表中的每一项
    repeat with currentItem in theList
        keystroke currentItem  -- 输入当前列表项内容
        keystroke return       -- 输入换行符
        delay 0.1  -- 可选:添加短暂延迟,避免输入过快导致系统无响应
    end repeat
end tell

原代码问题说明:

  • 语法错误:keystroke of varName写法错误,正确格式为keystroke varName
  • 列表项获取逻辑错误:set varName to (item 1) + condition无法正确定位下一个列表项,需通过索引直接访问列表元素
  • 循环冗余:使用repeat with...in可以更简洁地遍历列表,无需手动维护计数器变量

扩展用法(可选):

如果需要指定输入的目标应用,可在执行前激活对应应用,比如在备忘录中输入:

set theList to {"Apple Watch", "iMac", "iPhone", "MacBook Pro"}

activate application "Notes"  -- 激活备忘录应用
delay 0.5  -- 等待应用完成激活

tell application "System Events"
    repeat with currentItem in theList
        keystroke currentItem
        keystroke return
        delay 0.1
    end repeat
end tell

内容的提问来源于stack exchange,提问作者Rassy Raoof

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.24 06:36:11