Convert text file to html

Hello there, im pretty new in applescript and im looking for a script to
convert a single text file i a dir on my desktop to a html file, all the content
in my textfile should work like “url” in the html output.

Currently im using this script to make the txt file… maby this can be recoded
to send the html output


set the_folder to ("OS X:Users:mkh:Desktop:logs")
set the_log to ("WWW:test:myfile.txt:")

set file_list to list folder the_folder without invisibles
tell (a reference to AppleScript's text item delimiters)
    set {old_atid, contents} to {contents, return}
    set {file_list, contents} to {"" & file_list, old_atid}
end tell
my write_to_file(the_log, file_list, false)
beep

on write_to_file(the_file, the_data, with_appending)
    set the_file to the_file as file specification
    try
        open for access the_file with write permission
        if with_appending = false then set eof of the_file to 0
        write the_data to the_file starting at eof as (class of the_data)
        close access the_file
        return true
    on error the_error
        try
            close access the_file
        end try
        return false
    end try
end write_to_file

thanks in advance

mkh

something like this?

set myHeader to "<html><head><title>Converted with AppleScript!</title></head>
"
set endHTML to "
</html>"

set myFile to (choose file)
set myContents to (do shell script "cat " & quoted form of POSIX path of myFile)

set myHTML to myHeader & myContents & endHTML

set myFolder to (do shell script "dirname " & quoted form of POSIX path of myFile)
do shell script "cd " & quoted form of myFolder
do shell script "echo " & quoted form of myHTML & " > " & quoted form of myFolder & "/index.html"

i don’t entirely understand your question, but this is really basic. you may want to edit the HTML, and you may need to parse words to add HTML tags. this should get you started.

cheers.

Oh yes, you are my new best friend :smiley:

Hm, okay, this is working but im getting the output on 1 line

what i need is

line1
line2
ect

This will create a html file in the same directory as the txt file

set myFile to (do shell script "textutil -convert html  " & quoted form of (POSIX path of (choose file)))

Look at the Man page for textutil to see more options

Thanks for all the help…

uhm okay, this is almost as i want it to be :confused:

And now i found this, and by the look of it it is what i need
But im getting this error " Expected ", " or “}” but found ". "
in my script editor…

http://bbs.applescript.net/viewtopic.php?pid=26881#p26881

I too am having an issue with this and am getting the same error as above

HELP!!!

In that example you are referencing change this line

set end of body_string to {" <li><a href="", webserver_url, folder_name, "/", this_file, "">", this_file, "</a></li>", return}

to this

set end of body_string to {"            <li><a href=\"" & webserver_url & folder_name & "/" & this_file & "\">" & this_file & "</a></li>" & return}