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.
Sal
Sue
Bob
Carl
Wanda
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:
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:
Sal
Sue
Bob
Carl
Wanda
Egbert
Fred
Danita
Shirley
Scott
Quincy
Bertha
Jane
Julia
Frank
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:
Sal
Egbert
Quincy
Sue
Fred
Bertha
Bob
Danita
Jane
Carl
Shirley
Julia
Wanda
Scott
Frank
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:
IMPORTANT TIP: Learn how to save and run your favorite scripts using the system-wide Script Menu.
Populate New Table with Row-Based Data
01
propertyuseHeaders : true-- change to false to omit headers
02
propertydatasetCount : 6
03
propertydatasetItemCount : 3
04
05
tellapplication "Keynote"
06
activate
07
-- for this example script, generate some random data sets
Mention of third-party websites and products is for informational purposes only and constitutes neither an endorsement nor a recommendation. MACOSXAUTOMATION.COM assumes no responsibility with regard to the selection, performance or use of information or products found at third-party websites. MACOSXAUTOMATION.COM provides this only as a convenience to our users. MACOSXAUTOMATION.COM has not tested the information found on these sites and makes no representations regarding its accuracy or reliability. There are risks inherent in the use of any information or products found on the Internet, and MACOSXAUTOMATION.COM assumes no responsibility in this regard. Please understand that a third-party site is independent from MACOSXAUTOMATION.COM and that MACOSXAUTOMATION.COM has no control over the content on that website. Please contact the vendor for additional information.