2014-09-13 75 views
-1

此代码在打开的文件夹中创建一个新的html文件,然后告诉textedit打开它进行编辑。Applescript制作无法编辑的文件

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 

麻烦的是文字编辑与抱怨:

文件“的test.html”无法打开。您没有权限。

TextEdit有什么问题?

回答

0

打开命令需要一个文件对象或文件的路径:

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) 
+0

感谢您尝试帮助,但现在我得到一个对话框,说:“你确定你要修改的文件地点?' '就地修改文档可能会导致您丢失一些原始格式。你想先复制文件吗?' – aquagremlin 2014-09-13 18:05:37

+0

原来这是一个文本编辑问题。我会发布一个新问题。 – aquagremlin 2014-09-13 19:38:20