LNS Home
JavaScript OSA
JavaScript OSA Home
Download & Installation
QuickStart
Project Status
Documentation
 
Object Reference
 
Core
MacOS
MacOS.AEDesc
MacOS.AEApp
MacOS.AEClass
MacOS.AEColl
MacOS.FileSpec
MacOS.OSA
MacOS.MacOSError
Sending Raw AppleEvents
Responding to AppleEvents
AppleEvent to JavaScript Value Conversion
How-Tos
 
Open Handler
Folder Actions Handlers
Write Some Text
Calling JavaScript from REALbasic
Using JavaScript Libraries
FAQ
Mailing List
JavaScript Language Documentation & Links
Products
x Script Debugger 4.5
Site Contents
bullet Mark’s Blog
Product Registration
Bug Reporting
x Freeware
Contacting Us

MacOS.AEColl object

The MacOS.AEColl object represents a collection of elements within the target application. Instances of MacOS.AEColl are returned by properties of the MacOS.AEClass. MacOS.AEColl is a JavaScript array object that can be accessed by index (corresponding to the AppleScript by-index key form) or by string (corresponding to the AppleScript by-name) key form.

NOTE: AppleEvent indexes are 1-based and JavaScript array indexes are 0-based. MacOS.AEColl uses 1-based indexes, so care should be take to avoid confusion in your JavaScript code.

The MacOS.AEColl object provides the following properties and methods

Method/Property Description
MacOS.AEColl.length

sends a Count AppleEvent to the application returning the number of elements in the collection

MacOS.AEColl.every

returns a MacOS.AEClass object referring to all the elements of the collection

MacOS.AEColl.first

returns a MacOS.AEClass object referring to the first element in the collection

MacOS.AEColl.last

returns a MacOS.AEClass object referring to the last element in the collection

MacOS.AEColl.middle

returns a MacOS.AEClass object referring to the middle element in the collection

MacOS.AEColl.any

returns a MacOS.AEClass object referring to a random element in the collection

MacOS.AEColl.beginning

returns a MacOS.AEClass object representing an insertion location at the beginning of the collection

MacOS.AEColl.atBeginning
MacOS.AEColl.toBeginning

returns an instance of MacOS.AEDesc containing an insertion location suitable for use with the at parameter of make, copy, duplicate and move events

MacOS.AEColl.end

returns a MacOS.AEClass object representing an insertion location at the end of the collection

MacOS.AEColl.atEnd
MacOS.AEColl.toEnd

returns an instance of MacOS.AEDesc containing an insertion location suitable for use with the at parameter of make, copy, duplicate and move events

MacOS.AEColl.byID(idValue)

returns a MacOS.AEClass object referring to an element keyed by unique ID

MacOS.AEColl.byRange (loBound, hiBound)

returns a MacOS.AEClass object referring to a range of elements within the collection

NOTE: indexes are 1-based


The following example shows MacOS.AEColl in use enumerating the files on the MacOS Finder's desktop.

Sample
var names = "";

with (MacOS.finder())
{
    numFiles = file.length;
    for (i = 1; i <= numFiles; ++i)
    {
        if (names != "")
            names += ", ";
        names += file[i].name;
    }
}

// in AppleScript, this would be expressed as
//
// set names to ""
//
// tell application "Finder"
//     set numFiles to count files
//     repeat with i from 1 to numFiles
//         if names is not "" then ¬
//             set names to names & ", "
//         set names to names & (name of file i)
//     end repeat
// end tell

 


Copyright © 1998-2009 Late Night Software Ltd. - All Rights Reserved.