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

如何用AppleScript创建未保存的纯文本TextEdit窗口?

如何用AppleScript创建未保存的纯文本TextEdit窗口?

你的现有方案依赖模拟快捷键切换纯文本,存在不稳定(比如延迟不足、焦点丢失)的问题,更优的方式是直接通过TextEdit的AppleScript原生属性创建纯文本文档并设置内容,无需依赖UI操作:

set textContent to "my text and so on…"

tell application "TextEdit"
    activate
    -- 直接创建纯文本格式的新文档并填充内容
    set newDoc to make new document with properties {text: textContent, plain text: true}
end tell

关于你尝试的属性设置写法失效的原因:

  • TextEdit的文档对象没有Content这个属性,指定纯文本格式需要用plain text布尔属性(true表示纯文本,false表示富文本)。
  • set text of theDoc as plain text属于语法错误,正确的方式要么在创建文档时就通过with properties指定plain text: true,要么创建后单独设置:
    tell application "TextEdit"
        set textContent to "my text and so on…"
        activate
        set newDoc to make new document
        set plain text of newDoc to true
        set text of newDoc to textContent
    end tell
    

这种原生属性操作的方式比模拟快捷键更可靠,不会受系统延迟、窗口焦点的影响。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.03 15:32:35