Basics of AppleScript

Get List By Splitting Test

You have a text and you want to create a list by splitting the text by a delimiter. AppleScript allows us to specify the delimiter too.

Script [6.13.1]:

set myName to "Nayan Seth"
set oldDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to " "
set studentData to every text item of myName
set AppleScript's text item delimiters to oldDelimiters
get studentData

Explanation: Wow! That’s a pretty big Script for a tyro. Don’t worry its really very simple to understand.

First I created a variable named myName which contains String data that is "Nayan Seth".

By default AppleScript’s text item delimiters is "". So I created a variable oldDelimiters which stores default AppleScript’s text item delimiters. Now I change AppleScript’s text item delimiters to " ". Notice the space in delimiter.

Next I ask AppleScript to create a list studentData which will contain data of myName. But look closely it says use the text item in myName. text item is delimiter (" "). Now I change the AppleScript’s text item delimiters to default.

Finally I use get command to print studentData.

Figure 6.13.1

Figure 6.13.1 Split Text Using Delimiters