MACSCRPT Archives

October 2006

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:
Mon, 23 Oct 2006 16:08:24 -0400
Content-Type:
text/plain
Parts/Attachments:
text/plain (101 lines)
Mark,

	I'm just curious why you tell the finder to do this? I use the same  
method, but without the Finder tell. Is there something I don't know?


On Oct 20, 2006, at 4:34 PM, Mark Lively wrote:

> What I use a *LOT* is
>
> on tidreplace(sometext, intext, outtext)
> 	tell application "Finder"
> 		set tid to AppleScript's text item delimiters
> 		set AppleScript's text item delimiters to intext
> 		set sometext to every text item of sometext
> 		set AppleScript's text item delimiters to outtext
> 		set sometext to sometext as text
> 		set AppleScript's text item delimiters to tid
> 	end tell
> 	return sometext
> end tidreplace
>
> I have it in a library even.  It only does case sensitive replaces  
> so its not perfect.
>
> Another option you may want to consider is using sed through do  
> shell script.
>
>
> On Oct 20, 2006, at 4:20 PM, Eric Schult wrote:
>
>> I've been using ACME Script Widgets' "ACME Replace" command for so  
>> long I=
>>
>> barely remember how to search and replace strings within strings  
>> in vanil=
>> la
>> AS. However, I find myself needing to do that, because my ACME  
>> Replace
>> commands are hanging in some of my newer scripts in OS 10.3.8.  
>> (They neve=
>> r
>> error out; the script just never finishes running, and then script  
>> editor=
>>
>> crashes.)
>>
>> I've just written a vanilla AS variation that works, but I'm  
>> worried I'll=
>>
>> bump into errors when running this script on a very long string.  
>> Maybe
>> that's not an issue anymore, but I recall in earlier versions of  
>> the Mac =
>> OS
>> and AS having to bite off the task in blocks. Is that still true,  
>> and wha=
>> t
>> is the limitation?
>>
>> If anybody has a variation on the following  script that'll do the  
>> same
>> thing and handle large blocks of text in a more efficient manner,  
>> I'd rea=
>> lly
>> appreciate seeing an example of it.
>>
>> Thanx!
>>
>> WES
>>
>>
>> set myTextBlock to "This string contains more than one instance of  
>> the wo=
>> rd
>> 'foo', and 'foo' is the string I want to substitute with some  
>> other word
>> other than 'foo'."
>> set subString to "not_foo"
>>
>> set AppleScript's text item delimiters to "foo"
>> set stringList to text items in myTextBlock
>> set AppleScript's text item delimiters to ""
>>
>> set newString to ""
>> set stringCount to count of items in stringList
>> if stringCount is greater than 1 then
>>  repeat with i from 1 to count of items in stringList
>>   set thisString to item i in stringList
>>    if i is not stringCount then
>>     set newString to newString &  ¬
>>      (thisString & subString) as string
>>    else
>>     set newString to newString & thisString
>>    end if
>>  end repeat
>> end if
>>
>> return newString
>>

ATOM RSS1 RSS2