Automator可零代码创建文本编辑辅助工具:右键新建带时间戳的TextEdit文档、快速打开Terminal并cd至当前路径,或打包为独立App支持Dock一键调用。
用 automator 构建自定义文本编辑工具,核心是把重复性操作封装成可一键触发的服务或应用,不写代码也能实现“所见即所得”的编辑辅助功能。重点不在替代专业编辑器,而在补足系统原生缺失的快捷能力——比如当前文件夹新建文档、快速打开 terminal 编辑、或用 textedit 生成带时间戳的草稿。
在当前文件夹直接新建空白文本文件
这是最常用也最实用的基础功能。系统默认右键没有“新建文本文档”,但用 Automator 三分钟就能加上:
- 打开 Automator → 新建“快速操作”
- 搜索并拖入“运行 AppleScript”动作
- 粘贴以下脚本(自动在你右键点击的文件夹里创建 新建文本文档.txt):
on run {input, parameters}
set theFolder to (first item of input) as alias
set fileName to "新建文本文档.txt"
set newFile to (theFolder as string) & fileName
do shell script "touch '" & newFile & "'"
return input
end run - 保存为“新建文本文档”,启用后右键任意文件夹即可使用
右键一键用 TextEdit 打开新文档(带自动命名)
比起纯空白文件,有时需要立刻进入可编辑状态。这个方案会直接唤起 TextEdit 并新建一个文档,文件名含当前时间,便于归档:
- 同样新建“快速操作”,用“运行 AppleScript”
- 脚本内容改为:
on run {input, parameters}
set theFolder to (first item of input) as alias
set timeStamp to do shell script "date '+%Y-%m-%d_%H-%M'"
set fileName to "笔记_" & timeStamp & ".txt"
set newFile to (theFolder as string) & fileName
do shell script "touch '" & newFile & "'"
tell application "TextEdit"
open file newFile
end tell
return input
end run - 保存后,右键文件夹就能新建并自动打开,光标已就位,随时可写
右键打开当前路径的 Terminal 并自动 cd 进去
对常写命令行或用 Vim/NeoVim 编辑文本的用户,这相当于“编辑环境秒启动”:
- 新建另一个“快速操作”,同样用 AppleScript
- 粘贴脚本:
on run {input, parameters}
set theFolder to (first item of input) as alias
set posixPath to POSIX path of theFolder
if application "Terminal" is running then
tell application "Terminal"
do script "cd " & quoted form of posixPath in window 1
activate
end tell
else
tell application "Terminal"
do script "cd " & quoted form of posixPath
activate
end tell
end if
return input
end run - 启用后,在 Finder 中右键任意文件夹,选该服务,Terminal 就会跳出来且定位到该路径
进阶:把多个文本操作打包成独立 App
如果你习惯把这类工具放在程序坞或 Dock 里点一下就用,可以做成 .app 应用程序:
- 新建 Automator 文稿时选择“应用程序”类型
- 添加“运行 AppleScript”,写一个综合脚本:比如先弹出对话框让你选“新建纯文本”还是“新建 Markdown”,再按需执行对应逻辑
- 保存为 .app 文件(如“文本快编.app”),可拖进程序坞,双击即运行,不依赖 Finder 上下文
- 还能自定义图标:复制你喜欢的 App 图标(如 TextEdit 或 VS Code 的),在 .app 上按 Cmd+I → 点图标 → Cmd+V 替换

















