Here’s a handler that I made that uses Foundation and Bridge Plus library.
Pass it:
- List of Records
- List of Keys
get back a list of items, where the items are grouped by whatever Keys matched
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
use script "BridgePlus"
load framework
-- classes, constants, and enums used
property NSOrderedSet : a reference to current application's NSOrderedSet
property SMSForder : a reference to current application's SMSForder
property NSArray : a reference to current application's NSArray
property NSMutableArray : a reference to current application's NSMutableArray
on makeDUPEGROUP(listofRECS, dupegroupKEYS)
set dupeARRAY to NSMutableArray's array()
set sourceARRAY to NSArray's arrayWithArray:listofRECS
set valuesOFARRAY to SMSForder's subarraysFrom:listofRECS usingKeys:dupegroupKEYS outKeys:(missing value) |error|:(missing value)
set valuesUNIQUE to NSOrderedSet's orderedSetWithArray:valuesOFARRAY
repeat with i from 1 to count of valuesUNIQUE
set currentVALUES to (valuesUNIQUE's objectAtIndex:(i - 1)) as list
set indexMATCH to (SMSForder's indexesOfItems:{currentVALUES} inArray:valuesOFARRAY inverting:false) as list
set indexSET to (SMSForder's indexSetWithArray:indexMATCH)
set newOBJECT to (sourceARRAY's objectsAtIndexes:indexSET)
(dupeARRAY's insertObject:newOBJECT atIndex:(count dupeARRAY))
end repeat
return dupeARRAY as list
end makeDUPEGROUP
example use:
set listofRECS to {{plyINDX:2, entINDX:2, title:"Crazy in Love (ft. Jay-Z)", artist:"Beyoncé", depth:1, score:50}, ¬
{plyINDX:3, entINDX:6, title:"Bootylicious Elegance (Nesky Mashup)", artist:"Nesky", depth:3, score:30}, ¬
{plyINDX:2, entINDX:4, title:"No Diggity (Casual Connection 2016 Rework)", artist:"Blackstreet ft. Dr. Dre", depth:3, score:30}, ¬
{plyINDX:2, entINDX:5, title:"Sexy Ladies (Casual Connection Boogie Funk Rework)", artist:"Justin Timberlake", depth:4, score:20}, ¬
{entINDX:4, title:"Return of the Mack", plyINDX:1, depth:-1, score:50, artist:"Mark Morrison"}, ¬
{plyINDX:2, entINDX:3, title:"Bootylicious Elegance (Nesky Mashup)", artist:"Nesky", depth:2, score:40}, ¬
{plyINDX:2, entINDX:4, title:"No Diggity (Casual Connection 2016 Rework)", artist:"Blackstreet ft. Dr. Dre", depth:3, score:30}, ¬
{plyINDX:2, entINDX:5, title:"Sexy Ladies (Casual Connection Boogie Funk Rework)", artist:"Justin Timberlake", depth:4, score:20}, ¬
{plyINDX:2, entINDX:6, title:"Can I Kick It?", artist:"A Tribe Called Quest", depth:5, score:10}}
set dupegroupKEYS to {"title", "artist"}
set theResults to makeDUPEGROUP(listofRECS, dupegroupKEYS)
