First, you need an NSArray. Then something like this:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
property t_DataNamestoFMPnames : {{dataName:"flights_climbed", fmpName:"AH_FlightsClimbed"}, ¬
{dataName:"apple_exercise_time", fmpName:"AH_ExerciseTime"}, ¬
{dataName:"active_energy", fmpName:"AH_Active Energy"}}
set theData to current application's NSArray's arrayWithArray:t_DataNamestoFMPnames
set theResult to (theData's valueForKey:"dataName") as list
For filtering or matching, you need to use an NSPredicate:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
property t_DataNamestoFMPnames : {{dataName:"flights_climbed", fmpName:"AH_FlightsClimbed"}, ¬
{dataName:"apple_exercise_time", fmpName:"AH_ExerciseTime"}, ¬
{dataName:"active_energy", fmpName:"AH_Active Energy"}}
set theData to current application's NSArray's arrayWithArray:t_DataNamestoFMPnames
set thePred to current application's NSPredicate's predicateWithFormat:"dataName = %@" argumentArray:{"apple_exercise_time"}
set newList to (theData's filteredArrayUsingPredicate:thePred) as list
Absolutely perfect, Shane. Thank you ever so much! The rest of this is TMI but designed to express my gratitude for your measured approach to teaching these techniques.
I should have, but did not, connect that I needed an NSArray for the table. I have been developing a script to parse JSON data and of course I learned how and why to to use the NSArray. Just got so overwhelmed trying to understand the valueForKey that I missed the larger picture.
Due to your coaching in your book, I have also learned to seek answers in the Xcode developer documentation. Sadly, it never occurred to me to read the sections on Files and Sorting for a table lookup.
I have been scripting for about 10 years - nothing especially tough. I got interested in the idea of using ASObjc, bought your book and have been attempting to learn the new language. I must say that this is a difficult but rewarding adventure. I have now been able to parse JSON data, get text from a pdf (blazingly fast compared to my former process of using pdfPen), and now my current project - updating a Filemaker database from JSON data - replacing doing the same thing with csv files and Numbers.
Bought AppleScriptObjC Explored?Everyday AppleScriptObjC? Where? I’d kill for a copy, no matter how outdated. After all, AppleScript itself is arguably outdated, but we’re stuck with it.