Multiple TIDs


I can’t remember where or how I got text items with multiple delimiters before. For instance, ths:

set t to "abcdefgh"
set utid to AppleScript's text item delimiters
set AppleScript's text item delimiters to {"c", "f"}
set l to text items of t
set AppleScript's text item delimiters to utid
--> {"ab", "defgh"}

would return this:

→ {“ab”, “de”, “gh”}

I think it might have been used with text items of some text editor, in a tell block. Anybody know how this happened?



That’s alright. I was probably reading from file with this:

set f to choose file
set l to read f using delimiter {“c”, “f”}

Thanks anyway,

Hi Kel,

I did not know you could do that.

I notice that each item in the delimiter has to be one character.

Just had a play and found a way to use a complete string or a whole word, Not sure how useful it would be, but you never know :slight_smile:

set the_delim to characters of "the text I want to use " 
set new_file_path to (path to desktop as Unicode text) & "Test.txt"

set t to read file new_file_path using delimiter the_delim

Hi Mark,

‘using delimiters’ is good for getting a flat list instead of a list of paragraphs in delimited text file. For instance, in this tab delimited text file:

you could get easily get every item of field 2. e.g.

set lf to ASCII character 10
set f to choose file
set l to read f using delimiter {tab, lf}
set c to count l
set field_items to {}
set field_index to 1
set field_count to 2
repeat with i from 1 to c by field_count
	set this_item to item (i + (field_index - 1)) of l
	set end of field_items to this_item
end repeat

Instead of getting every paragraph, repeating through that list, and getting the items from field 2, you can step through the flat list.


I must be tired or something I thought your snippet would return the name or number but it looks like it returning the text file ?

here is my result window I just copy and pasted your code

{"joe    20
mary    30
sally    40
bob    50"}

Hi kel,

the differences are:

Text item delimiters can be a list, but only the first (also multiple character) item is used

b using delimiters[/b] can be list, all items (but only the first character of them) are used

Hi Stefan,

I don’t get what you’re saying.


Hi Macgrailm,

When I copied the text from the quote, the tabs where replaced by 5 spaces. I made my own text file.


Sorry, I try it simpler

¢ your example for text item delimiters

set t to "abcdefgh"
set AppleScript's text item delimiters to {"bc", "f"}
-->{"a", "defgh"}

if multiple items are defined, only the first (“bc”) is effective, all others are ignored,
but the delimiter can contain more than one character

¢ the other example with read using delimiter

set f to choose file --> assuming "abcdefgh"
set l to read f using delimiter {"cd", "f"}
--> {"ab","de","gh"}

In this case all items of the delimiter list can be used, but the delimiter can only be one character,
so only the first character ist effective, if there are more than one character

Hi Stefan,

That’s an interesting observation. So, what you want to use a delimiters, should be characters that are not used in the text.


Please read the last part of my post again, Kel
I’ve edited it, because there was a mistake in it

Yes. That’s why I said that this can be used to flatten a list. Then you use the math to do the walking.

I don’t get what you’re saying.


Just use the default delimiter {“”}, therefore it’s strongly recommended to reset
the text item delimiters always after changing it

set a to {"a", "b", "c", "d", "e"}
set b to a as string
--> "abcde

I apologize for my confusing English

Hi Stefan,

Yes, that’s right. You can read with delimiters but not write. Good observation.