How to add repeat code to this script?

I am using a very good script from regulus6633 to convert some
XXXX.website files to
XXX.rtfd files

this is the original script


set textutilPath to "/usr/bin/textutil"

-- get the input html file and variables
set htmlFile to choose file with prompt "Choose the HTML file to convert to rtfd:" without invisibles

-- calculate the output rtfd path
set rtfdPath to (htmlFile as text) & ".rtfd"

-- convert html to rtfd
do shell script quoted form of textutilPath & " -format html -convert rtfd -output " & quoted form of POSIX path of rtfdPath & space & quoted form of POSIX path of htmlFile

I add a repeat loop as I have hundred of files in that folder


set inputfolder to (choose folder)
set htmlFile to list folder inputfolder without invisibles

repeat with x from 1 to count of htmlFile
	set textutilPath to "/usr/bin/textutil"
	
	set rtfdPath to (htmlFile as text) & ".rtfd"
	do shell script quoted form of textutilPath & " -format html -convert rtfd -output " & quoted form of POSIX path of rtfdPath & space & quoted form of POSIX path of htmlFile
	do shell script "textutil -convert txt " & (inputfile)
end repeat


the error i get is this

Result:
error “Can’t make quoted form of POSIX path of {" XXXX.webarchive"} into type Unicode text.” number -1700 from quoted form of POSIX path

I certainly do something wrong how can i fix the script?

Thanks a lot

Model: Mac Pro, Quad-Core Intel Xeon
Browser: Safari 533.19.4
Operating System: Mac OS X (10.6)

Hi,

your script cannot work, because you never use the index variable x.
htmlFile is a list, which cannot be coerced to text.
I haven’t tested it, but try this


set inputfolder to (choose folder)
tell application "Finder" to set htmlFiles to files of inputfolder

repeat with aFile in htmlFiles
	set aFilePath to (aFile as text)
	set rtfdPath to aFilePath & ".rtfd"
	do shell script "/usr/bin/textutil -format html -convert rtfd -output " & quoted form of POSIX path of rtfdPath & space & quoted form of POSIX path of aFilePath
end repeat


Thanks Stephan … it obviously work well
Still however I need to move all the files in the main folder as the script will not “scan” the subfolders" but only the main folder …

Is there a way to tell the finder to convert the files it will find from the chosen folder but also in the subfolders included inside it … and

could I get the same result result (a repeat script scanning a chosen foder and its subfolders) with the sript you helped me with a few days ago:

so all files can be processed and not one by one while staying in the original folder or moved to a new one keeping the original folder-subfolder sturcture?



set rtfdFile to (choose file with prompt "Choose the RTFD file." of type "com.apple.rtfd")
set fileName to text 1 thru -6 of name of (info for rtfdFile)
set destFolder to POSIX path of (choose folder with prompt "Choose the folder the unpack the RTF")
set packageContents to list folder rtfdFile

-- copy RTF file
if "TXT.rtf" is not in packageContents then
	display alert "No Valid RTFD" message "The chosen file is not a valid RTF file with attachmetns. The 'TXT.rtf'-file was not found."
	return
end if
set rtfSource to POSIX path of rtfdFile & "TXT.rtf"
do shell script "/usr/bin/ditto " & quoted form of rtfSource & space & quoted form of (destFolder & fileName & ".txt")


-- copy attachments
set attFolder to destFolder & fileName & " Attachments/"
repeat with i in packageContents
	if (contents of i) is not "TXT.rtf" then
		do shell script "/usr/bin/ditto " & quoted form of (POSIX path of rtfdFile & i) & space & quoted form of (attFolder & i)
	end if
end repeat

Thanks again and regardså

Danwan

Model: Mac Pro, Quad-Core Intel Xeon
Browser: Safari 533.19.4
Operating System: Mac OS X (10.6)