I am making a cocoa applescript osx app in Xcode 5
I have a Table View that is updated with the current play time of a quicktime file with each button press using an Array Controller. All is working well but I am stuck on how to then save the results of the Table view to file, preferably a .csv
I have been trying to research ways to do this but most of the tutorials I find relate to iOS. I have researched using NSStrings and writeToFile but am having trouble filling in the blanks.
I have tried binding the table content of the table view to an Array Controller in IB with a Key Path of FinalResults and then on the save button sender
FinalResult's writeToFile:FilePath
FilePath being a location set using
set FilePath to choose folder
It is building successfully but when I press the Save button it is giving me the following error
the contents of an array controller (aka arrangedObjects()) is usually a list/array of records/dictionaries.
The method to write an instance of NSArray to disk is writeToFile:atomically:, the format of the resulting file is property list
I thought would share the results here in case anybody was searching for the same thing
set filePath to POSIX path of (path to desktop) & "test.csv" -- sample path, change it something appropriate
set theArray to arrayController's arrangedObjects() -- arrayController is a property connected to an NSArrayController instance
set csvList to current application's NSMutableArray's array()
csvList's addObject:((theArray's objectAtIndex:0)'s allKeys()'s componentsJoinedByString:",")
repeat with anItem in theArray
(csvList's addObject:((anItem's allValues())'s componentsJoinedByString:","))
end repeat
set csvText to (csvList's componentsJoinedByString:return)
csvText's writeToFile:filePath atomically:true encoding:(current application's NSUTF8StringEncoding) |error|:(missing value)