Mac Finder 新建文本文件
2019-10-16 本文已影响0人
五城十九洲
打开自动操作.app

添加一个工作流 ,选取应用程序
,在左边栏–资源库
–实用工具
中选择运行AppleScript
,将下方代码替换掉默认代码


代码:
on run {input, parameters}
tell application "Finder"
set selection to make new file at (get insertion location)
end tell
return input
end run
关闭Automator
,会提示你保存,保存到 应用程序
文件夹,然后Finder 工具栏右键, 自定义, 把 New File.app 拖到工具栏的空白位置即可。点击一下,即可生成文本文件。


升级弹出提示框,输入文件名,只需更改以下代码
tell application "Finder"
try
-- 获取Finder顶层窗口的文件夹路径并转换为替身
set new_txt_path to the folder of the front window as alias
-- 文件名对话框
display dialog "Enter File Name: (default .txt)" default answer "untitled"
on error
return
end try
try
-- 尝试新建空白文本文件
set filename to the text returned of result
if filename does not contain "." then
set filename to filename & ".txt"
end if
make new file at new_txt_path with properties {name:filename}
on error eText number eNum
-- 如果发生错误,并且错误代码为-48(即文件已存在),则提示用户
if eNum is equal to -48 then
display dialog "File exists" with title "Error" with icon caution giving up after 5
end if
end try
end tell
