Okay, well, here’s the big picture: I’m writing a book in .rtf, using DevonThink. What I want is to write an AppleScript that will convert that .rtf into .html and then email it to my @kindle account, so that I can in one stroke transfer a copy of my book to my Kindle. Since the Kindle is very basic in terms of reading html tags, I want to use TextWrangler to edit the html, removing most of the junk, and replacing it with the simple tags
,
, and (as well as adding the custom Kindle page break tag, <mbp:pagebreak />.
So anyway, here’s the beginning of the Applescript I’ve written - which works fine (with one slight issue*). The search strings are simply the more complex html tags that the DevonThink converter put into the document. (Each line in the original html ends with ).
tell application id "com.devon-technologies.thinkpro2"
set theselection to selection
repeat with therecord in theselection
set theConvertedRecord to convert record therecord to html
export record theConvertedRecord to "/Users/writing/Desktop/Converted"
end repeat
end tell
tell application "TextWrangler"
activate
replace "<div align=\"center\" class=\"div0\"><font class=\"font0\">" searching in "/Users/writing/desktop/Converted" using "<mbp:pagebreak /><h1><center>"
replace "<div align=\"center\" class=\"div1\"><font class=\"font0\">" searching in "/Users/writing/desktop/Converted" using "<p><center>"
replace "<div align=\"justify\"><font class=\"font0\">" searching in "/Users/writing/desktop/Converted" using "<p>"
replace "</font></div>" searching in "/Users/writing/desktop/Converted" using ""
What I end up with after these commands is an html document where, in the html body lines, each line has the proper beginning tags (either
or
, sometimes with ). But none of these lines has any end tag at all.
So what I want to do is to instruct TextWrangler to append the suffix “
” to every line in these documents. I’ve done this manually and the document comes out working great.
Here’s what I’ve tried: (continuing from above)
set theFolder to "/Users/writing/desktop/Converted"
repeat with theFile in theFolder
repeat with theLine in theFile
add suffix "</p></h1></center>"
end repeat
end repeat
But I get the following error message: "Textwrangler got an error (MacOS Error code -1701). It highlights the Applescript line that begins “add suffix.”
So that’s the whole story (so far)!
Thanks in advance to everyone for your help.
-
- the problem with this early part of the script is that I have to click a Confirm Save dialogue every time a replace command is finished - “Save changes before continuing?” – so I guess I need to put in some kind of “save document” line after each replace, correct?