AppleScript to instant sort Tilia-ready data

The software Tilia, well known from palaeoecologists, needs the user to specify a group code for each taxa. The obvious question after that, is to sort all these data so that taxa with the same group code are gathered together. One could use the custom sort fonction from Excel, or use this AppleScript:

tell application "Microsoft Excel"

    tell active sheet

        set GroupList to {"CONC", "LABO", "CHAR", "CNFR", "TREE", "SHRB", "CULT", "PAST", "HERB", "MANS", "CYPC", "UNID", "ANAC", "WETL", "VACR", "PLNT", "TCOV", "COPR", "FUNG", "ALGA", "DINO", "AMOB", "ANIM", "pNPP", "uNPP"} -- A list of custom taxa groups. All taxa must have been specified one of them!

        add custom list list array GroupList -- this makes Excel aware of the custom list

        set ListID to get custom list num list array GroupList -- this tells us which ID Excel assigned to our custom list

        set LastCell to get address of last cell of used range -- with LastCell, we can then easily specify a particular range od data (ie starting at row 3) to keep the first two rows unsorted

        sort special range ("A3:" & LastCell) ¬
            key1 (range "G:G") ¬
            order1 sort ascending ¬
            header header no ¬
            order custom ListID

    end tell

end tell

You can easily adapt the definition of GroupList to match the group names you are familiar with 😉

Posted by Benjamin

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.