Populating Tables with Data

Tables are meant to hold data. That’s obvious. So the question you’re probably asking now is: using scripting, how do you get data into a table? The answer is: the script iterates the data one bit at a time, and places each bit in its corresponding table cell.

Huh?

It makes sense, once you understand that it’s all about the data and how it is read. You see, table data is grouped by either row or column.

For example, let’s examine this list of names (remember that in AppleScript, lists are contained within curly braces, and contain comma-delimited items) :

{"Sal", "Sue", "Bob", "Carl", "Wanda"}

The list contains five names. If this list was to be used as the data for a row, it would require a single row that would span at least five columns, one for each name.

SalSueBobCarlWanda

However, if this list was to be used as the data for a column, it would require a single column that would span at least five rows, one for each name.

Sal
Sue
Bob
Carl
Wanda

Makes sense, right? If the data is for a row, there has to be a column for each item in the data list. If the data is for a column, there has to be a row for each item in the data list.

Now, let’s add some more data. Instead of having just one list of five names, let’s have three lists of five names, fifteen names in total, all combined into a parent list (think of it as a “list of lists”), like this:

{{"Sal", "Sue", "Bob", "Carl", "Wanda"}, {"Egbert", "Fred", "Danita", "Shirley", "Scott"}, {"Quincy", "Bertha", "Jane", "Julia", "Frank"}}

If this data is to be read as rows, there would be a row for each list item (that’s three rows), and each row would span five columns (the number of items in each list item), like this:

SalSueBobCarlWanda
EgbertFredDanitaShirleyScott
QuincyBerthaJaneJuliaFrank

If this data is to be read as columns, there would be a column for each list item (that’s three columns), and each column would span five rows (the number of items in each list item), like this:

SalEgbertQuincy
SueFredBertha
BobDanitaJane
CarlShirleyJulia
WandaScottFrank

Not to be overly repetitious, but as you can see, it’s all about how the data is read: row or column. So all a script has to do to populate a table, is to read the data and place into one row at time, or one column at a time.

Example Scripts

The two example scripts below, demonstrate how scripts can create and populate tables based upon whether the data is read as row-based, or as column-based:

TOP | CONTINUE