AppleScript";另存为;文本编辑中的HTML
我希望AppleScript循环遍历文件夹中的一组RTF文件,并将它们保存为HTML文件 这是迄今为止我的简单代码。XXXX是我挣扎的地方:AppleScript";另存为;文本编辑中的HTML,applescript,textedit,Applescript,Textedit,我希望AppleScript循环遍历文件夹中的一组RTF文件,并将它们保存为HTML文件 这是迄今为止我的简单代码。XXXX是我挣扎的地方: tell application "Finder" set source_folder to choose folder set aList to every file in source_folder repeat with i from 1 to number of items in aList tell app
tell application "Finder"
set source_folder to choose folder
set aList to every file in source_folder
repeat with i from 1 to number of items in aList
tell application "TextEdit"
set aFile to (item i of aList)
save as aFile XXXXXXXXX
end tell
end repeat
end tell
我对这个真的很陌生。。。非常感谢您的帮助。您不需要进行文本编辑。有一个命令行程序textutil,它可以在不打开和保存textexedit所需的所有内容的情况下完成任务。我们可以修复您的文本编辑脚本(它有一些错误),但请先尝试一下,让我们知道它是否适合您。html文件将具有相同的名称,但具有html扩展名,并将位于source_文件夹中。可以使用textutil的“-output”开关在代码中更改输出路径。如果您想了解它所能做的一切,请参阅“man textutil” 还有一个一般性的问题。。。什么是RTD文件?你是说rtf还是rtfd?Textutil将使用rtf/rtfd,但不能使用rtd,因此我希望这不是您真正的文件类型
set source_folder to choose folder with prompt "Choose a source folder."
set output_folder to choose folder with prompt "Choose an output folder."
tell application "Finder"
set theFiles to (files of entire contents of source_folder) as alias list
end tell
repeat with aFile in theFiles
tell application "Finder"
set fileName to name of aFile
set fileExt to name extension of aFile
end tell
set outputPath to (output_folder as text) & text 1 thru -((count of fileExt) + 1) of fileName & "html"
do shell script "/usr/bin/textutil -convert html -output " & quoted form of POSIX path of outputPath & space & quoted form of POSIX path of aFile
end repeat
您提到您是applescript新手,所以我将给您一些在编写applescript代码时应该记住的一般性提示
所以我希望这能有所帮助!祝你好运。你不需要进行文本编辑。有一个命令行程序textutil,它可以在不打开和保存textexedit所需的所有内容的情况下完成任务。我们可以修复您的文本编辑脚本(它有一些错误),但请先尝试一下,让我们知道它是否适合您。html文件将具有相同的名称,但具有html扩展名,并将位于source_文件夹中。可以使用textutil的“-output”开关在代码中更改输出路径。如果您想了解它所能做的一切,请参阅“man textutil” 还有一个一般性的问题。。。什么是RTD文件?你是说rtf还是rtfd?Textutil将使用rtf/rtfd,但不能使用rtd,因此我希望这不是您真正的文件类型
set source_folder to choose folder with prompt "Choose a source folder."
set output_folder to choose folder with prompt "Choose an output folder."
tell application "Finder"
set theFiles to (files of entire contents of source_folder) as alias list
end tell
repeat with aFile in theFiles
tell application "Finder"
set fileName to name of aFile
set fileExt to name extension of aFile
end tell
set outputPath to (output_folder as text) & text 1 thru -((count of fileExt) + 1) of fileName & "html"
do shell script "/usr/bin/textutil -convert html -output " & quoted form of POSIX path of outputPath & space & quoted form of POSIX path of aFile
end repeat
您提到您是applescript新手,所以我将给您一些在编写applescript代码时应该记住的一般性提示