我经常使用此服务在当前打开的文件夹中创建一个新的文本文件:
tell application "Finder"
set txt to make new file at (the target of the front window) as alias
select txt
end tell
但是如果我可以创建一个 RTF,那就更有用了。然而,在谷歌搜索和 GPT 搜索之后,我无法让它工作。有人为自己编写过类似的服务吗?
这不是超级优雅,但你可以将空 RTF 文档的数据写入新创建的文件中:
tell application "Finder" to set txt to (make new file at Finder window 1) as alias
try
set fileHandle to open for access (POSIX path of txt) with write permission
write "{\\rtf1\\ansi\\ansicpg1252\\cocoartf2757
\\cocoatextscaling0\\cocoaplatform0{\\fonttbl}
{\\colortbl;\\red255\\green255\\blue255;}
{\\*\\expandedcolortbl;;}
\\paperw11900\\paperh16840\\margl1440\\margr1440\\vieww11520\\viewh8400\\viewkind0
}" to fileHandle
close access fileHandle
on error err number num
display dialog err & " number " & num buttons {"OK"} default button 1 with title "File I/O Error..." with icon caution
try
close access fileHandle
end try
return
end try
tell application "Finder" to select txt
如果您在 TextEdit 中打开 RTF,这将生成一个正常运行的 RTF。