Home » Poor Man's AppleScript HTML Export Online Documentation
h2. Poor Man's AppleScript HTML Export

This example AppleScript will talk to the first document, gather all the pages, and then export them as pre-formatted html to the folder specified in the variable "outFolder"

<carea class="textareaCodeLarge">-- this is the path to the folder you would like to write out to.
set outFolder to "srv:Users:gus:Desktop:html"
tell application "VoodooPad"
    repeat with i from 1 to number of items in pages of document 1
        set s to text of page i of document 1
        set n to name of page i of document 1
        
        set s to my findAndReplace("&", "&amp;", s)
        set s to my findAndReplace("<", "&lt;", s)
        set s to my findAndReplace(">", "&gt;", s)
        
        set outfile to outFolder & ":" & n & ".html"
        set outText to "<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>Here the title</title></head><body><pre>" & s & "</pre></body></html>"
        
        tell application "Finder"
            set f to outfile
            set nref to open for access file f with write permission
            set eof nref to 0
            write outText to file f
            close access nref
        end tell
    end repeat
end tell
-- shamelessly stolen from http://bbs.applescript.net/viewtopic.php?id=13008
on findAndReplace(tofind, toreplace, TheString)
    set ditd to text item delimiters
    set text item delimiters to tofind
    set textItems to text items of TheString
    set text item delimiters to toreplace
    if (class of TheString is string) then
        set res to textItems as string
    else -- if (class of TheString is Unicode text) then
        set res to textItems as Unicode text
    end if
    set text item delimiters to ditd
    return res
end findAndReplace</carea>