MACSCRPT Archives

October 2008

MACSCRPT@LISTSERV.DARTMOUTH.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Paul Skinner <[log in to unmask]>
Reply To:
Macintosh Scripting Systems <[log in to unmask]>
Date:
Fri, 3 Oct 2008 12:31:33 -0400
Content-Type:
text/plain
Parts/Attachments:
text/plain (134 lines)
Interesting.

What this does is reads your source, and spits out a properly formated  
RTF file. Here it works splendidly. Why you're getting that error I'm  
not sure. I suspect it's getting garbled in the exchange.

If you want to try it already compiled, you can download it from http://idisk.mac.com/paulskinner-Public?view=web 
  under "Applescript stuff". It's named "Read and parse underscores to  
italics.app.zip".

I am on 10.5.5. What's your OS version? What's your applescript  
verision? You can just run "version" to get it.

Paul


On Oct 3, 2008, at 11:59 AM, RJay Hansen wrote:

> Hmmm... It comes back with a -1700 error: Can't make "{\\rtf1\\ansi\ 
> \ansicpg1252\\cocoartf949\\cocoasu.... etc. into text.
>
> I'm not understanding what the purpose of that part of the script is  
> for?
>
> rjay
>
>
> On Oct 2, 2008, at 5:17 PM, Paul Skinner wrote:
>
>> 	This version should be able to handle any filesize that the read  
>> command can handle. No text accumulation, it writes as it reads. I  
>> think this is pretty solid; I'll stop now.
>>
>>
>> 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 "}"
>> 	
>> 	try
>> 		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 as text
>> 	on error e number n
>> 		display dialog "Error: " & (n as text) & return & e
>> 	end try
>> 	
>> 	set textoutput to {}
>> 	
>> 	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 (text 1 thru -2 of currentChunk) & (ASCII character 32)  
>> & "\\i " to outputFileHandle as text
>> 				end if
>> 				set evenOddOpenCloseItalicsToggle to 1
>> 			else
>> 				write ((text 1 thru -2 of currentChunk) & (ASCII character 32)  
>> & "\\i0" as text) to outputFileHandle as text
>> 				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 as text
>> 	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 Oct 2, 2008, at 5:40 PM, Paul Skinner wrote:
>>
>>> This got me to thinking and I knocked this out. It generates a  
>>> file named "(originalFilename)_Italicized.rtf" right next to the  
>>> source file you choose. Let me know how this does on you r large  
>>> text file, I'm curious.
>> ...
>>>
>>>
>>> On Oct 2, 2008, at 4:36 PM, RJay Hansen wrote:
>>>
>>>> On Oct 2, 2008, at 1:59 PM, Bill Steele wrote:
>>>>
>>>>> Unless you need this to happen in front of people's eyes, you  
>>>>> don't have to do it in Tex-Edit. You can operate on an  
>>>>> Applescript string variable with the search features in the ACME  
>>>>> Script Widgets or Satimage OSAXen.
>>>>
>>>> Can you do the text styling though? From what I've been able to  
>>>> determine, you can't although I'd be happy to be shown I'm wrong.
>>>>
>>>>> Finding what's between two underscores also could be a regular  
>>>>> expression job.
>>>>
>>>> I actually thought of this yesterday when someone on the A.S.S.  
>>>> list mentioned regular expressions. However, I've got that part  
>>>> of the script working fine. I suspect using regular expressions  
>>>> to do that would be quicker, but what I've got goes pretty fast.
>>>>
>>>> RJay

ATOM RSS1 RSS2