10.0 Changes

This article describes changes to AppleScript and related tools in Mac OS X v10.0.

Mac OS X v10.0 - AppleScript 1.6

AppleScript 1.6 is included with Mac OS X version 10.0 and requires Mac OS X version 10.0 or later.

Developer Notes

  • A new call, OSACopyScript(), will create an independent clone of an existing OSAID. OSACopyID(), by comparison, creates a new reference to an existing object.

  • Event handlers have always been able to accept an as parameter, but have had no way to indicate to AppleScript that they handled the coercion. This creates problems when the handler actually returns a list of the requested type -- AppleScript thinks the list needs to be coerced, and tends to either fail or do the wrong thing. The workaround has been to define a “type list” type and a coercion handler from that to a plain list that simply duplicates the descriptor. The Finder’s alias list type, for example, is implemented this way. There is now a better way: if you take an as parameter, and you do not want AppleScript to try to coerce your result, put a Boolean true value into the keyAppHandledCoercion parameter of the result. AppleScript will sense this parameter and leave the result unchanged.

  • Mac OS X does not support scripting additions (OSAXen) built for Mac OS 9. Because only applications can safely link to CarbonLib on Mac OS 9, scripting additions on 9 must link to InterfaceLib, which is not supported on Mac OS X. Scripting additions for Mac OS X come in two flavors: CFM and Mach-O. For CFM, follow the directions in Tech Note TN1164 to build it as a shared library, but link to CarbonLib instead of InterfaceLib.

  • Mach-O scripting additions are packaged as bundles. Using Project Builder, create a Bundle target, and make sure that it has either a CFBundleSignature of 'osax' or a name ending with .osax. The code layout is essentially the same as a CFM scripting addition, but instead of using the CFM initialization and termination routines plus the gAdditionReferenceCount global, AppleScript looks for three entry points: SAInitialize, SATerminate, and SAIsBusy, with the following prototypes:

  • additionBundle is a reference to your own addition; you may retain it for future use or ignore it and rely on your own bundle identifier. SAIsBusy is equivalent to testing for gAdditionReferenceCount not equal to zero.

  • It is possible to build a bundled scripting addition that contains both 9 and X versions, thus giving you a single file distribution, but you need to have AppleScript 1.6 and CarbonLib 1.3 installed on Mac OS 9.1 for it to work with Mac OS 9.

  • An important difference from Mac OS 9 is that in Mac OS X, scripting additions are loaded separately into each application that connects to AppleScript. This means that (1) there may be multiple instances of your addition running on the system, so be careful about shared resource management; and (2) you cannot assume that any random application has access to your addition, so sending raw AppleEvents to an application will not necessarily work. (e.g., sending syso/beep to the Finder will return not handled.) AppleScript has a workaround built into it so that scripts will still work, but applications that use AppleEvents directly may have trouble.

New Features and Enhancements

AppleScript

  • The Unicode text data type has been growing in functionality since AppleScript 1.3 and is now comparable in functionality with the string data type. Not only can Unicode text strings be received from and sent to applications, they display properly in the Results and Event Log windows of the Script Editor (and third-party editors); they can be accessed with the character, word, paragraph, and text item element classes and the first, last, middle, some, and every access forms; they can be operated on with the & (concatenation) operator; and they can be compared with the less than, greater than, less than or equal to, greater than or equal to, equals, contains, is contained by, begins with, and ends with operators. For text item elements of a Unicode string, the text item delimiters can be either string or Unicode text values. When comparing Unicode strings, the considering and ignoring constructs are supported for case, diacriticals and punctuation.

  • AppleScript 1.6 supports many changes in general system operation introduced in Mac OS X. It can use applications and scripting additions that are stored as bundles or packages for Mac OS X. It can load scripts and application terminologies from files that do not have traditional Mac OS resource forks. It accommodates the fact that many Mac OS X applications actually have a .app filename extension that is hidden from the user.

Command Line Tools

  • There are two new command line tools, osascript and osacompile, that let you execute and compile scripts from a Unix shell. For full details, see their respective man pages.

Bug Fixes

AppleScript

  • AppleScript 1.6 fixes a long-standing issue in AppleScript in which scripts may claim to run out of memory, even when plenty of memory is available.

  • AppleScript 1.4.3 and 1.5.5 had rare issues with applets losing track of global variables; these issues have been fixed in AppleScript 1.6.

  • AppleScript 1.6 returns more correct results from certain unusual operations (item 0 of a list, set text item delimiters to {}, strings of a string, strings of a list that doesn’t contain strings) where previous versions of AppleScript would return unhelpful results or fail to signal appropriate errors.

Standard Additions

  • AppleScript 1.6 has improvements to the random number command, to make random numbers more evenly distributed and less predictable.

  • The read and write commands can now work with files greater than 2 GB in size. In addition, all of the issues introduced in the Read/Write commands in AppleScript 1.5 and 1.5.5 have been fixed, and several long-standing issues with reading and writing lists and records have been fixed.

  • Copyright © 2001-2007 Apple Inc.