• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Record sorting routine
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Record sorting routine


  • Subject: Re: Record sorting routine
  • From: Kai <email@hidden>
  • Date: Sun, 09 Feb 2003 13:06:56 +0000

on Sat, 8 Feb 2003 13:40:36 -0600, "Jerry Podhajsky" <email@hidden>
wrote:

> I have a list of records that I'd like to sort by a date field contained
> in all the records. I'm trying to roll my own with Applescript, but
> have come up short and very confused.
>
> Does anyone have a basic Applescript routine (I'm trying to avoid an
> OSAX, so that I can see the code and maybe learn something) that takes a
> list of records and sorts them by a specified field in the record?

Try something like this, Jerry:

=======================================

to sortRecords from rList
if rList's length < 2 then return rList
set {l, h, {m, s}} to {{}, {}, rList's {item 1, rest}}
repeat with r in s
if m's d > r's d then
set l's end to r's contents
else
set h's end to r's contents
end if
end repeat
if l's length > 1 then set l to sortRecords from l
if h's length > 1 then set h to sortRecords from h
l & {m} & h
end sortRecords

sortRecords from putYourRecordListHere

=======================================

Depending on how your records are set up, you may need to modify the first
line of the repeat loop (which currently reads: 'if m's d > r's d then').

Firstly, unless the date label in your records just happens to be 'd', then
substitute your own date label.

Secondly, if your dates are entered in a text format (such as "5/3/1995"),
they'll need coercing to a date - so the repeat loop should start with
something like this instead:

=======================================

if date (m's d) > date (r's d) then

=======================================

--
Kai
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Mail or Smile bug ?
  • Next by Date: Re: Adding an attachment to Entourage
  • Previous by thread: Re: Record sorting routine
  • Next by thread: RE: Record sorting routine
  • Index(es):
    • Date
    • Thread