AppleScript Text and List Processing in Mac OS 9

In the classic Mac OS 9 operating system, AppleScript managed text manipulation and list processing through an English-like syntax centered on chunk expressions, native list data types, and a global property called text item delimiters. While the language was deeply integrated into the system for automating Finder operations and third-party publishing applications, it lacked built-in regular expressions and modern data algorithms. As a result, developers relied on specific language idioms, referencing techniques, and third-party Scripting Additions (OSAXen) to efficiently parse strings and manipulate structured collections.

Text Manipulation in Mac OS 9

AppleScript approached text through hierarchical components known as "chunks." Scripts could directly query and extract elements using intuitive descriptors:

  • Characters, Words, and Paragraphs: Text could be segmented by intrinsic structural boundaries. A script could call first word of textVar, characters 1 thru 5 of textVar, or every paragraph of textVar. AppleScript determined word boundaries using localized punctuation and whitespace rules defined by Mac OS 9's language settings.
  • Text Item Delimiters: The primary mechanism for splitting and joining strings was the global property AppleScript's text item delimiters. By default, this was set to an empty string ({""}). By reassigning this delimiter, developers could split a string into a list or join a list into a string:
    set oldDelims to AppleScript's text item delimiters
    set AppleScript's text item delimiters to {","}
    set theList to text items of "apple,banana,cherry"
    set AppleScript's text item delimiters to {" - "}
    set theString to theList as text
    set AppleScript's text item delimiters to oldDelims
    Restoring the original delimiter was a required practice; failing to do so could disrupt subsequent string operations across the script or other running scripts.
  • Encoding Limitations: Mac OS 9 relied predominantly on the legacy MacRoman character encoding. While AppleScript 1.3.7 and later introduced basic support for the Unicode text class, string manipulation predominantly occurred within MacRoman single-byte boundaries, which sometimes created parsing quirks when interacting with international text or nascent web standards.
  • Scripting Additions (OSAX): Because AppleScript lacked native regular expressions, complex searching, and string replacement functions, power users installed Scripting Additions—most notably the Satimage OSAX or ACME Script Widgets—into the System Folder:Scripting Additions directory to perform pattern matching and fast string mutations.

List Processing in Mac OS 9

Lists in AppleScript were ordered, heterogeneous collections capable of holding numbers, strings, records, references, or nested lists:

  • Creation and Access: Lists were defined with curly braces (e.g., set myList to {"A", 1, true}). Elements were accessed using 1-based indexing, negative indexing, or chunk ranges. Commands such as item 1 of myList, item -1 of myList (the last item), and items 2 thru 4 of myList allowed standard slice retrieval.
  • Concatenation and Coercion: The ampersand operator (&) joined lists together ({1, 2} & {3, 4}) or appended individual items. Coercing a list to a string automatically utilized the current state of AppleScript's text item delimiters.
  • Iteration: Loops were typically written as repeat with anItem in myList or indexed via repeat with i from 1 to count of myList. However, iterating directly through large collections with repeat with anItem in myList had a notable quirk: the loop variable held a reference pointer to the item rather than a raw value, often requiring the explicit contents of anItem statement to evaluate properly.
  • Performance Bottlenecks and Reference Tricks: In Mac OS 9, AppleScript's internal memory management meant that operations on lists with hundreds or thousands of items slowed down exponentially. To bypass the linear-time lookup overhead, developers used a widely adopted performance idiom: placing the list inside a script object and accessing elements through a reference.
    script FastList
        property internalList : {}
    end script
    
    set FastList's internalList to largeList
    repeat with i from 1 to count of FastList's internalList
        set thisItem to item i of FastList's internalList
    end repeat
    Accessing list items via a reference pointer (a reference to or through a script property) converted the linear \(O(n)\) search lookup into a near-constant-time operation, dramatically speeding up data processing routines in Mac OS 9.