Tuesday, September 27, 2022

#1 2022-08-17 09:06:31 am

From:: Greece
Registered: 2019-03-03
Posts: 2524

Choose From Record (otherwise, "get subrecord")

Choose From  Record dialog handler:


set subRecord to chooseFromRecord({Person:"KniazidisR", City:"Athens", Phone:"+3 698 00000000", Company:false})

on chooseFromRecord(aRecord as record)
   -- get all existing keys as list
   set oldCliboard to the clipboard
   set the clipboard to aRecord
   set aRecordAsList to the clipboard as list
   set {theKeys, theValues} to {{}, {}}
   repeat with i from 1 to count aRecordAsList by 2
       set end of theKeys to item i of aRecordAsList
       set end of theValues to item (i + 1) of aRecordAsList
   end repeat
   set the clipboard to oldCliboard
   -- select some keys set from all keys
   set newKeys to choose from list theKeys with multiple selections allowed
   if newKeys is false then return
   -- get corresponding values list
   set newValues to {}
   repeat with i from 1 to count theKeys
       set thisKey to item i of theKeys
       if newKeys contains thisKey then set end of newValues to item i of theValues
   end repeat
   -- Create a list containing keys subsequently followed by it's associated value
   set rawList to a reference to {}
   repeat with i from 1 to count newKeys
       tell rawList to set {end, end} to {item i of newKeys, item i of newValues}
   end repeat
   -- Create a record who is similar to records containing only user defined keys in AppleEvents
   set rawRecord to «class seld» of (record {«class usrf»:rawList} as record)
end chooseFromRecord

NOTE: I know, getting sub record without user interacting is simpler. But requires the explicit indicating for key-value pairs. I the sub record  to get in the result is big, it will be somewhat problematic:


set sourceRecord to {Person:"KniazidisR", City:"Athens", Phone:"+3 698 00000000", Company:false}
tell sourceRecord to set subRecord to {Person:its Person, Phone:its Phone}

Last edited by KniazidisR (2022-08-17 09:42:10 am)

Model: MacBook Pro
OS X: Catalina 10.15.7
Web Browser: Safari 14.1
Ram: 4 GB



Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)