我有一个创建 html 文件并使用 textedit 打开它们的applescript:
try
tell application "Finder" to set save_folder to (target of window 1) as alias
on error
set save_folder to path to desktop
end try
set textFile to (choose file name with prompt "Enter file name:" default location save_folder default name "Comment.html") as text
if textFile does not end with ".html" then set textFile to textFile & ".html"
do shell script "touch " & quoted form of POSIX path of textFile
tell application "Finder"
set file type of (textFile as alias) to "html"
set creator type of (textFile as alias) to "sfri"
end tell
tell application "TextEdit"
open file textFile
activate
end tell
该文件以锁定状态打开,这很痛苦。但是,如果我将文件类型和创建者设置为 TEXT 和 ttxt(TextEdit 的标识符),那么一切都很好。我讨厌为了编辑html文件而不得不授予对textedit的root访问权限,但我想这就是需要的吗?我想我可以切换到另一个文本编辑器,但我有一个问题,为什么 TextEdit 会以这种方式处理 html 文件?