• 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: Sorting lists of strings and lists of lists in Applescript
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sorting lists of strings and lists of lists in Applescript


  • Subject: Re: Sorting lists of strings and lists of lists in Applescript
  • From: Christopher Stone <email@hidden>
  • Date: Tue, 18 Mar 2014 07:09:26 -0500

On Mar 18, 2014, at 00:07, Alastair Leith <email@hidden> wrote:
I found a "sortlist" command in the applescript dictionary
______________________________________________________________________

Hey Alastair,

Not exactly.  As you note later it's from the Satimage.osax - a 3rd party osax.

but I can't get it to work for me.

Well, that doesn't make sense.  Rearranging your list to make the sort even more obvious and then running the exact same sort:

set random_list to {¬
"prada", ¬
"penny", ¬
"swati", ¬
"teddy", ¬
"james", ¬
"adam"}

set sorted_list to sortlist random_list ¬
ascending true ¬
remove duplicates false ¬
comparison 1

--> Result:

{
"adam", 
"james", 
"penny", 
"prada", 
"swati", 
"teddy"
}

When I pasted the command into Script Debugger it was not wrapped with tell statements

Nor should it be.

but I tried wrapping it in tell application "Finder" in case.

These days we're told to avoid putting osax-calls within application tell-blocks.

There is this comment in the dictionary but I don't know what it refers to — the links are dead:
(from the Array and List Utilities suite, defined in Satimage.osax)

The links should NOT be dead.  If in fact they are it's indicative of something amiss.

Make sure you're using the most recent version of the Satimage.osax.

Even if you are it might be a good idea to reinstall it.

Reboot your system for good measure.

The dictionary description suggests this command will also sort a list of lists using the "with respect to" argument by prioritising the criteria with integers (presumably like a table sort in a spreadsheet app but no example or specification is provided).

The best place to ask questions about the Satimage.osax or Smile is Smile Users List.

In short _javascript_ has an inbuilt sort for array objects method: my_array.sort(a,b) does Applescript have anything similar?

No.  Nothing built-in, but you can shell out to Perl, Python, Ruby, _javascript_, etc.

--
Best Regards,
Chris

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >Sorting lists of strings and lists of lists in Applescript (From: Alastair Leith <email@hidden>)

  • Prev by Date: Sorting lists of strings and lists of lists in Applescript
  • Next by Date: Re: Sorting lists of strings and lists of lists in Applescript
  • Previous by thread: Sorting lists of strings and lists of lists in Applescript
  • Next by thread: Re: Sorting lists of strings and lists of lists in Applescript
  • Index(es):
    • Date
    • Thread