0
我有一個創建的HTML文件,並使用文本編輯打開它們一個AppleScript:爲什麼TextEdit將html文件打開爲鎖定狀態?
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文件而必須給root權限以textedit,但我想這就是需要的嗎?我可以切換到另一個文本編輯器,但我留下了一個問題,爲什麼TextEdit採用HTML文件的方式?
謝謝您的解決方案,但我相當希望通過textedit – aquagremlin 2014-09-26 03:46:15
這個行爲的'under hood'解釋這是因爲TextEdit必須重寫文件(HTML格式無效),所以它必須有你的權限來覆蓋文件。 當文檔被鎖定時,只需輸入一個字符,Textedit會詢問您是否要覆蓋HTML文件,就是這樣,不需要root訪問 – jackjr300 2014-09-29 03:12:19