Hi all,
First off, I’m totally new to applescript studio, this is the very first attempt at writing anything with it…
I’m trying to dynamically create TableView columns.
Searching through the forum has been a great help so far but I cannot find the info I need to progress…
I am reading a csv file into a table view with no problems, but using a hard coded number of columns. I now want to be able to dynamically create the necessary columns on the fly, depending on the number of items in the csv file.
I have a check box on a window called “Main Window” to indicate if the file has headers.
Current file format example
USER, ID, TestID, Type, Valid
20666554,9985,558,0,0
Here is small portion of what I have written
-- Has the user indicated that the first line of the file contains header info?
-- True or False
set fileContainsHeaders to content of button "containsHeaders" of window "Main Window"
-- code omitted to keep this short
-- read the file
-- This is the data from the file
set num_list to paragraphs of (read_file)
if fileContainsHeaders then
set {TID, text item delimiters} to {text item delimiters, ","}
set firstItems to text item 1 of num_list
-- This is where I want to get the number of items and then create the correct number columns
-- and give them header titles as per the header line in the csv file
end if
When I use
display dialog firstItems as string
I can see that it returns … “USER, ID, TestID, Type, Valid”
What I now need to be able to do is count the number of items in that string - in this case it would be 5, and then dynamically create these in a table view.
Is there an applescript string function that I can use to count the items?
I am then thinking that once I get the number of items I would use “set number of Columns …” to the number I get and then use a
“repeat with” to set the “Header Title” for each column.
Can anyone point me to what functions I need to get the number of items in the string, and how to add colums to a table view?
Thanks and regards
John.