Subject: | |
From: | |
Reply To: | |
Date: | Fri, 3 Oct 2008 16:53:43 -0500 |
Content-Type: | text/plain |
Parts/Attachments: |
|
|
Initially I got:
"Can't get text item delimiters"
When I looked at your endlines handler I noticed you only had "text
item delimiters" rather than "AppleScript's text item delimiters".
Changing that fixed that issue, and yes, I got a nice new document
broken up into paragraphs.
I finally got the one I've been writing finished and got it to run w/
no errors. For comparison, on the same text file (420K) it takes just
over a minute to run, versus the don't-blink-or-you'll-miss-it time
of Paul's effort. And Paul's script runs about 16K versus my 40K.
Interestingly, Paul's/Mark's script seems to have got lost toward the
end of the book, and missed(?) an underscore, so the last two and a
half chapters are bass-ackwards as far as plain styled vs. italic
styled, while my script didn't do that. :-/
RJay
On Oct 3, 2008, at 2:27 PM, Mark Lively wrote:
> try
> set head to "{\\rtf1\\ansi\\ansicpg1252\\cocoartf949\\cocoasubrtf350
> {\\fonttbl\\f0\\fswiss\\fcharset0 Helvetica;}
> {\\colortbl;\\red255\\green255\\blue255;}
> \\margl1440\\margr1440\\vieww12240\\viewh15840\\viewkind1
> \\pard\\tx720\\tx1440\\tx2160\\tx2880\\tx3600\\tx4320\\tx5040\
> \tx5760\\tx6480\\tx7200\\tx7920\\tx8640\\ql\\qnatural\\pardirnatural
>
> \\f0\\fs24 \\cf0 "
> set tail to "}"
>
> tell application "Finder"
> activate
> set inputFile to choose file with prompt "Choose an underscore
> delimited plaintext file for input."
> set inputFileName to name of inputFile
> set AppleScript's text item delimiters to "."
> copy text item 1 of inputFileName to inputFileName
> set AppleScript's text item delimiters to ""
> set inputFilePath to ((container of inputFile) as alias) as text
> end tell
>
> set inputFileHandle to open for access inputFile
> set outputFileHandle to open for access file (inputFilePath &
> inputFileName & "_Italicized.rtf") with write permission
> write head to outputFileHandle
>
> set evenOddOpenCloseItalicsToggle to 0
> repeat
> try
> set currentChunk to read inputFileHandle until "_"
> if evenOddOpenCloseItalicsToggle is 0 then
> if currentChunk is "_" then
> write ((ASCII character 32) & "\\i " as text) to
> outputFileHandle as text
> else
> write (endlines(text 1 thru -2 of currentChunk) & (ASCII
> character 32) & "\\i " as text) to outputFileHandle
> end if
> set evenOddOpenCloseItalicsToggle to 1
> else
> if currentChunk is "_" then
> write ((ASCII character 32) & "\\i0" as text) to outputFileHandle
> else
> write (endlines(text 1 thru -2 of currentChunk) & (ASCII
> character 32) & "\\i0" as text) to outputFileHandle
> end if
> set evenOddOpenCloseItalicsToggle to 0
> end if
> on error e number n
> if n is not -39 then display dialog "Error: " & (n as text) &
> return & e
> exit repeat
> end try
> end repeat
> write tail to outputFileHandle
> try
> close access inputFileHandle
> close access outputFileHandle
> end try
> on error e number n
> display dialog "Error: " & (n as text) & return & e
> end try
>
> on endlines(sometext)
> set tid to text item delimiters
> set text item delimiters to ASCII character 10 -- in 10.5 you can
> use linefeed instead
> set sometext to text items of sometext
> set text item delimiters to "\\" & (ASCII character 10)
> set sometext to sometext as text
> set text item delimiters to return
> set sometext to text items of sometext
> set text item delimiters to "\\" & return
> set sometext to sometext as text
> set text item delimiters to tid
> return sometext
> end endlines
|
|
|