MACSCRPT Archives

May 2010

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:
Mark Lively <[log in to unmask]>
Reply To:
Macintosh Scripting Systems <[log in to unmask]>
Date:
Fri, 21 May 2010 11:25:51 -0400
Content-Type:
text/plain
Parts/Attachments:
text/plain (62 lines)
On May 21, 2010, at 10:53 AM, Bill Steele wrote:

> 
> Interesting.  They seem to be set to "#". Xunno how that happened.
> But should Applescript be putting a text item delimiter into a concatenation?
> 

Yes, because you are stringing together text items.  Normally the text item delimiters are {""} so when you concatenate two strings together there is nothing between them.  They were set up as an easy way to jump back and forth between lists and strings.

For instance 

set myList to {1,2,3,45}
set text item delimiters to ", "
set myText to myList as text
--"1, 2, 3, 45"

or

set mytext to "Apples, oranges, mangos, pineapples"
set text item delimiters to ", "
set myList to text items of mytext
--{"Apples", "oranges", "mangos", "pineapples"}

But it is also used for build lists.

set outText to ""
set text item delimiters to ".  "
repeat
	set myText to text returned of (display dialog "What is the next line of the story?" default answer "")
	set outText to outText & myText
	if myText = "" then exit repeat
end repeat
outText

tell application "AppleScript Editor"
	display dialog "What is the next line of the story?" default answer ""
		--> {text returned:"There once was a little programmer", button returned:"OK"}
	display dialog "What is the next line of the story?" default answer ""
		--> {text returned:"He was looking for a good example", button returned:"OK"}
	display dialog "What is the next line of the story?" default answer ""
		--> {text returned:"He decided to write a program to insert a period at the end of every sentence", button returned:"OK"}
	display dialog "What is the next line of the story?" default answer ""
		--> {text returned:"", button returned:"OK"}
end tell
Result:
"There once was a little programmerHe was looking for a good exampleHe decided to write a program to insert a period at the end of every sentence"



Some sneaky people have used it for a very fast text replace

set myText to "I have 115 pairs of socks and 11 pairs of shoes."
set text item delimiters to "11"
set myText to text items of myText
set text item delimiters to "eleventy"
set myText to myText as text
--"I have eleventy5 pairs of socks and eleventy pairs of shoes."

Good style says put it back the way you found it.

-Mark
Of course there are ways to go to paranoid extremes.

ATOM RSS1 RSS2