此代码在打开的文件夹中创建一个新的html文件,然后告诉textedit打开它进行编辑。
tell application "Finder"
tell application "Finder" to set currentDir to (target of front Finder window) as text
make new file at currentDir with properties {name:"test.html"}
tell application "TextEdit"
activate
open ("test.html")
end tell
end tell
麻烦是Textedit抱怨:
无法打开文档“test.html”。您没有权限。
TextEdit有什么问题?
答案 0 :(得分:0)
open命令需要文件对象或文件路径:
tell application "Finder"
set currentDir to (target of front Finder window) as text
set htmlfile to make new file at currentDir with properties {name:"test.html"}
end tell
tell application "TextEdit" to open htmlfile
#This will probably open the HTML file in your default browser.
#Try this to open the file with TextEdit
do shell script "open -a textedit " & quoted form of POSIX path of (htmlfile as text)