1
我正在爲FoldingText設計一個script,它將FoldingText輪廓(基本上是一個Markdown文本文件)轉換爲一個Remark演示文稿(一個HTML腳本,可以從Markdown文件製作幻燈片)。該腳本的作品,但我想做出以下改進:保存當前文檔爲.html具有相同的名稱和路徑
而不是要求名稱和位置來保存HTML文件,我想抓住當前文件的名稱,並將其另存爲當前文件夾中的HTML文件(具有相同的名稱)。如果已經有一個具有該名稱的文檔(提供寫入文檔或另存爲具有不同名稱的新文檔),該腳本將很好地失敗。
我用來寫入文件的腳本來自這些論壇。第一部分是:
on write_to_file(this_data, target_file, append_data) -- (string, file path as string, boolean)
try
set the target_file to the target_file as text
set the open_target_file to ¬
open for access file target_file with write permission
if append_data is false then ¬
set eof of the open_target_file to 0
write this_data to the open_target_file starting at eof as «class utf8»
close access the open_target_file
return true
on error
try
close access file target_file
end try
return false
end try
end write_to_file
,第二部分是:
set theFile to choose file name with prompt "Set file name and location:"
my write_to_file(finalText, theFile, true)
感謝。
感謝您幫助我找到了我正在尋找的東西。目前沒有錯誤處理,它只是將HTML附加到完整的文件名。如果文件存在,更好的腳本會提供「另存爲」,並且會在追加.html之前剝離現有的.md,.txt或.ft擴展名。但現在這工作正常。 '告訴應用程序前面的文檔 「FoldingText」 集thedocument提交申請的 「FoldingText」 集NEWPATH前文件,以((thedocument作爲字符串)名 「.html」) 端告訴 我write_to_file(finalText,NEWPATH ,真)' – Kerim 2013-03-02 06:22:09
嗯。它不會讓我以我想要的方式格式化代碼,5分鐘後它告訴我我無法再編輯。這是修改後的腳本的[鏈接](http://support.foldingtext.com/discussions/questions/357-script-to-generate-remark-formatted-html-file-form-foldingtext#comment_25496591)。 – Kerim 2013-03-02 06:30:08
注意:如果您運行兩次,此腳本將追加,而不是覆蓋現有文件,這會產生問題。不知何故需要避免。 – Kerim 2013-03-02 06:42:08