Not at all.
I too find long AppleScript lists and records abysmally difficult to read and maintain.
Regular AppleScript records are not particularly useful due to their glaring limitations, and I've assiduously avoided using them as much as possible for decades.
But - AppleScriptObjC changes the ballgame.
Shane no doubt will improve upon this at least a bit.
# Auth: Christopher Stone
# dCre: 2017/02/24 21:05
# dMod: 2017/02/25 00:24
# Appl: AppleScriptObjC
# Task: Converting a text table to a NSDictionary for lookups.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @ASObjC, @Converting, @Text, @Table, @NSDictionary, @Lookups
-------------------------------------------------------------------------------------------
use framework "Foundation"
-------------------------------------------------------------------------------------------
property nsDict : missing value -- stub for dictionary
property recordTable : "
CDG Charles Degaulle – Paris – France
DFW Dallas/Fort Worth International Airport – USA
HND Haneda - Tokyo – Japan
IAD Dulles - Washington DC – USA
LHR Heathrow – London – United Kingdom
OKC Will Rogers World Airport - Oklahoma City - USA
ORD O'Hare International Airport – Chicago – USA
PER Perth – Western Australia – Australia
SYD Sydney – New South Wales – Australia
"
-------------------------------------------------------------------------------------------
if nsDict = missing value then
# Remove leading and trailing vertical whitespace:
set recordTable to (its cngStr:"\\A\\s+|\\s+\\Z" intoString:"" inString:recordTable)
set recNameList to paragraphs of (its cngStr:"(?m)\\t.+$" intoString:"" inString:recordTable)
set recValueList to paragraphs of (its cngStr:"(?m)^.+\\t" intoString:"" inString:recordTable)
set nsDict to current application's NSDictionary's dictionaryWithObjects:recValueList forKeys:recNameList
end if
set lookupValue to "OKC"
return lookupInDictionary(lookupValue)
-------------------------------------------------------------------------------------------
--» HANDLERS
-------------------------------------------------------------------------------------------
on cngStr:findString intoString:replaceString inString:dataString
set anNSString to current application's NSString's stringWithString:dataString
set dataString to (anNSString's stringByReplacingOccurrencesOfString:findString withString:replaceString ¬
options:(current application's NSRegularExpressionSearch) range:{0, length of dataString}) as text
end cngStr:intoString:inString:
-------------------------------------------------------------------------------------------
on lookupInDictionary(recName)
set returnResult to nsDict's objectForKey:recName
if returnResult = missing value then
return false
else
return returnResult as text
end if
end lookupInDictionary
-------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------
property recordTable : "
CDG Charles Degaulle – Paris – France
DFW Dallas/Fort Worth International Airport – USA
HND Haneda - Tokyo – Japan
IAD Dulles - Washington DC – USA
LHR Heathrow – London – United Kingdom
OKC Will Rogers World Airport - Oklahoma City - USA
ORD O'Hare International Airport – Chicago – USA
PER Perth – Western Australia – Australia
SYD Sydney – New South Wales – Australia
"
-------------------------------------------------------------------------------------------
set lookupValue to "OKC"
if fndUsing((lookupValue & "\\t+(.+)$"), "\\1", recordTable, false, true) of me ≠ false then
return result
else
error "Lookup value not found!"
end if
-------------------------------------------------------------------------------------------
--» HANDLERS
-------------------------------------------------------------------------------------------
on fndUsing(_find, _capture, _data, _all, strRslt)
try
set findResult to find text _find in _data using _capture all occurrences _all ¬
string result strRslt with regexp without case sensitive
on error
false
end try
end fndUsing
-------------------------------------------------------------------------------------------