AppleScript 1.3.2 and 1.3.4 (Mac OS 8.5 and 8.5.1)

NEW BUGS IN MAC OS 8.5 and 8.5.1

AppleScript 1.3.2 contained a bug which caused applets to leak memory whenever a scripting addition was called outside an application tell block. The bug was described in Tech Info Library article AppleScript 1.3.2: Memory Leak Affects Stay Open Scripts. The fix was applied in AppleScript 1.3.4 released with Mac OS 8.5.1, as confirmed in Tech Info Library article About Mac OS 8.5.1 Update. [FIXED IN 8.5.1]

In October 1998, Andy Bachorski of Apple confirmed this memory leak, which occurs when any scripting addition is called outside of a tell block in an applet. The bug was fixed in AppleScript 1.3.4, released as part of the Mac OS 8.5.1 update. Paraphrasing Andy, this bug was related to how events are handled in the applet shell component. This was a remnant of the work to take AppleScript native. Also, since applets are run using an AppleScript component, any applet which runs under 8.5 will have this leak, not just those created and saved under 8.5. The workaround before the 1.3.4 fix was to always put osax calls inside a tell block. They will run a bit slower since the event needs to be sent to another process, but you will avoid a leak in applets which need to say running. The bug was that each time a scripting addition is used a small amount of memory (about 40 bytes) is leaked until the script applet is quit. The memory leak is very small and is unlikely to affect a script applet unless it is a stay-open applet. Since may applets run and quit immediately they are usually not affected. The types of applets most likely to be affected are things like CGIs which run continuously. Unless you are writing CGIs or other script applications which need to stay running continuously, there aren’t any problems with AppleScript which will cause you any grief, and the many newly scriptable parts of the system will most likely be a benefit. 10/10/99

In March 1999, Chris Espinosa of Apple mentioned that a bug in AppleScript 1.3.2 and older causes stay-open applets to be called by the system continuously, thus hogging CPU time and slowing down other applications. The workaround is to include an idle handler that returns a nonzero sleep time [such as 30 seconds]… The applet will then only be invoked when an event is sent to it (like dropping a file on it), or every 30 seconds, whichever comes first. Without this idle handler, the applet is called as frequently as possible, which consumes CPU time. 10/10/99

Apple Help for AppleScript unit types refers to a ‘quart’ unit type for liquid measure. It is not in fact supported in AppleScript 1.3.2 or 1.3.4. This will be fixed in the next version.

In November 1998, Chris Espinosa of Apple reported a bug in AppleScript 1.3 that only manifests itself in Main Event Software’s Scripter script editor. Paraphrasing, Scripter uses certain obsoleted AppleScript programming interfaces (APIs) that nobody else uses (and aren’t tested because they’re obsolete), and a bug in the PowerPC conversion made one of those APIs unavailable. It only affects Scripter’s Call box when calling script handlers. Cal Simone has a fix for it in Scripter, but I don’t know his update schedule. We’ll fix it in AppleScript in the next update release. Again, we don’t think this affects anything but the Call box in Scripter. [A newer version of Scripter fixes this problem when running under Mac OS 8.5 or 8.5.1, and Mac OS 8.6 fixes it even for older versions of Scripter.] 10/10/99

Rich Love has reported a bug that occurs when converting real numbers to strings in AppleScript. I don’t know whether this is new to AppleScript 1.3. To see the failure under OS 8.5…

property RealNumber : 0.0 as realproperty 
myVar : 0.0 as real
on run   
		set RealNumber to 1.12      
		set myVar to RealNumber as string -- This is the problem line   
	end repeat
end run

Running the above program will quickly cause you to run out of memory and crash. It uses up 64 bytes of memory each time it goes through the repeat loop. This same routine works perfectly in OS 8.1 The other real bad thing about this is that it seems to corrupt the whole applescript system in memory so that it affects other programs that are running that are using AppleScript. Re-booting after the memory problem is the only cure. 10/10/99

In the its-a-feature-not-a-bug category, Andy Bachorski confirmed that Apple deliberately removed the trademark symbol from some file names, which may affect some existing scripts which contain hard-coded file names. Paraphrasing Andy: we decided that the names of items from Apple shouldn’t have a TM in their names, so we removed it from names where it appeared. Part of the reason was it made localization of components a bit easier. [Unfortunately, this later caused difficulty for some when installing Mac OS 8.6. See Mac OS 8.6: Folders That Are Removed (TIL #60383 6/4/99).] 10/10/99

The Standard Additions dictionary incorrectly describes the result returned by the ‘choose from list’ command. The dictionary says it returns a list of strings to display (an empty list if no selection). In fact, the result is false, not an empty list, when the Cancel button is clicked, and the OK button is disabled if nothing is selected so pressing the Cancel button is the only way to get a result out of it. The description should say a list of strings to display (false if no selection), or, better yet, a list of strings to display (false if canceled). 10/10/99

AppleScript 1.3 is the first new version of AppleScript since version 1.1.2 was released with Mac OS 8.0 in July 1997. The first public release in the 1.3 series was AppleScript 1.3.2, released on October 17, 1998 with Mac OS 8.5. It was quickly updated to AppleScript 1.3.4, released on December 7, 1998 with Mac OS 8.5.1. The only change in version 1.3.4 is a memory leak bug fix affecting AppleScript applications (applets); the bug was introduced in AppleScript 1.3.2. 10/10/99

Like the note on AppleScript 1.1.2, this note is in large part a mixture of information obtained from various sources, including mostly Apple’s own publications and the terminology dictionaries of scriptable system components. It is interlaced with news and commentary that I have figured out for myself through experimentation or picked up from the AppleScript mailing lists.


Products relating to AppleScript will be upgraded or released to work with the new and changed features of Mac OS 8.5. Known compatibility issues are listed here.

PreFab’s Scott Lawton has reported that testing shows only these problems using the popular PreFab Player utility with Mac OS 8.5: Player doesn’t see the names of dialog items (but ID & XY work); set value of checkbox isn’t reliable; and the OS 8.0/8.1 popup problem.

In the final testing of Folder Action Setup 1.0.1, I discovered that Kensington MouseWorks 5.0.4 (in particular, the Kensington Startup system extension) is incompatible with FaceSpan applications when running Mac OS 8.5. In some cases (including Folder Action Setup), the Kensington software prevents a FaceSpan application’s windows from appearing, and it renders the Quit menu and its keystroke equivalent inoperable. It was reported elsewhere recently that the Kensington software also prevents buttons from appearing in Microsoft Word 98 dialogs, when running Mac OS 8.5. I have verified this. Version 5.0.5b1 of the Kensington software solves both problems.

WestCode Software has set up a page where you can track their progress in making OneClick compatible with Mac OS 8.5. 10/10/99

AppleScript 1.3 represents a major advance in AppleScript’s development. These new features are notable:

AppleScript is now PowerPC native, resulting in an estimated threefold to fivefold improvement in execution speed of basic AppleScript commands. This, combined with the immense increase in hardware speed in the new G3 Macs, makes for a radically different user experience when running scripts. The About AppleScript document indicates that AppleScript 1.3 cannot be used with versions of the operating system older than Mac OS 8.5. Furthermore, because it is native, it cannot be used on 680x0 Macintosh computers (which cannot in any event run Mac OS 8.5). Note that the speed increase does not extend to Apple events sent to applications, because the Event Manager remains mostly emulated 680x0 code.

Paraphrasing a summary of the speed issue by Andy Bachorski of Apple: The Apple Event Manager (AEM) and Process Manager are 68K. The AppleScript (AS) OSA component is native. AS only used the AEM to send events to other processes. Other than that it doesn’t rely on the AEM for anything else. Many of the osaxen in the Standard Additions scripting addition are native, though not all. Osaxen are loaded by AS, but called by the AEM. Coercion handlers, again loaded by AS and called by the AEM, are a mixed bag, with the unit types being 68K code (so trivial they wasted time being native) and Unicode coercions being native, as examples. The overall performance of AppleScript is improved, especially any scripts which do a lot of their own work (numeric calculations, etc.), though you can find specific cases where native AppleScript is a bit slower than the non-native version. 10/10/99

The terminology dictionaries of basic system scripting facilities have been reorganized to reflect a more logical organization. This change is particularly evident in the scriptable Finder’s dictionary. The old Required Suite of four basic commands has been eliminated and their commands distributed among other suites, and new functional categories now organize commands and object classes into a more readable and understandable form.

A new Scripts folder exists at the root level of the System Folder, as an optional standardized location for users’ scripts. A new Folder Action Scripts subfolder appears here automatically, for example, as an optional location to place folder action scripts. The Scripts folder has long been known to users of Leonard Rosenthol’s OSA Menu, a utility that places a Scripts menu in the menubar. OSA Menu Lite is now provided as an optional feature of the operating system.

Many more features of the operating system have become scriptable. These now include the following control panels, system extensions, applications and feature-specific scripting additions: Appearance, Apple Data Detectors Scripting, Apple Help Viewer, Apple IR File Exchange, Apple Menu Options, Apple System Profiler, Apple Video Player, Application Switcher, ColorSync, ColorSync Extension, Desktop Printer Manager, Desktop Printing, Disk Copy, Disk First Aid, File Exchange, File Sharing, File Sharing Commands, Find (Sherlock), Folder Actions, Internet, Keyboards, Keyboard Addition, Location Manager, MonitorDepth, Network Setup Scripting, OSA Menu, Remote Access Commands, Set Volume, SNMP Administrator, Users & Groups, Web Sharing and Web Sharing Extension. And, of course, the Finder. In an interesting new twist, some of the features of some of the new system components are available only through an AppleScript interface. The Application Switcher is a notable example of this, and it has spawned a dozen free and shareware applications based on Apple events. Apple’s official AppleScript web site contains Mac OS 8.5 Scripting Overview, a growing collection of articles and example scripts for scripting these scriptable system components.

Third-party software distributed by Apple on the system installation CD-ROM is also scriptable. Examples include Iomega Tools, StuffIt Expander and, of course, Microsoft Internet Explorer and Microsoft Outlook Express.

Several items in Mac OS 8.5 have scripting dictionaries (terminology, or ‘aete’ resources) but are not in fact scriptable. I understand this is an artifact of the development system used to create them. They include: the Apple Data Detectors control panel.

Many formerly separate scripting additions have been consolidated into a single Standard Additions scripting addition, which also now includes new commands. The old separate scripting additions have the same interface and functionality in the new location (except for the addition of the new timeout parameter to ‘display dialog’). The following formerly separate scripting additions have been incorporated into Standard Additions and should be removed from your Scripting Additions folder if present: AGStart, Beep, Choose Application, Choose File, Current Date, Display Dialog, File Commands, Load Script, Numerics, String Commands, Read/Write Commands, Run Script, Store Script and Time To GMT.

Several new commands have been added to existing scripting additions. These include the clipboard commands from the popular Jon’s Commands scripting addition; the ‘delay’ command to pause script execution without stealing processor cycles from other operations; the ‘choose from list’ command to display and select from a user-defined list of text items, from the popular and venerable GTQ Scripting Additions package; the ability to mount remote volumes from Leonard Rosenthol’s MountVolume scripting addition; the ‘say’ command for speech synthesis that was formerly an optional install as part of Apple’s Text-to-Speech software; a command to summarize complex text into an arbitrarily small number of sentences; and the ability to display dialogs that go away automatically after a user-defined interval. In addition, plain English terminology has been provided for a number of scripting commands which formerly required use of obscure raw Apple event codes. These include the ‘reopen’ event and three new terminology suites for Internet data types, Mac OS connectivity and folder actions. Some of these allow Common Gateway Interface (cgi) scripting on web servers using plain English. Many new selectors are added for the ‘path to’ command that is now part of the Standard Additions scripting addition. Some existing commands may have new names after you compile existing scripts under Mac OS 8.5, but they will work the same. A few existing scripts may require rewriting.

Units of measure can be used to convert between measurement systems. For example, ‘x as meters’ can be converted to feet simply by writing ‘x as feet’. Lawrence D’Oliveiro has published his thoughts on Mac OS 8.5 units. Andy Bachorski of Apple has described the units feature as follows, paraphrasing: The implementation of unit types in AppleScript is very simplistic and was the best that could be done given the current limitations of the language. It was never intended to be used as a tool for doing higher mathematics, but rather as a tool that would allow script writers to designate a unit of measure to be associated with a value which can then be sent to an application where that unit is interpreted, scaled, and applied to the target object. Responding to a mathematician’s suggestions, Andy decscribed the syntax as follows: Unfortunately, there is no direct support for units in AppleScript, which prevents us from using pure mathematical syntax. An alternative syntax is also supported, though, with somewhat limited functionality. That syntax is ‘set x to meter: 12’. With the current implementation you can write statements like ‘x as cm’, which will perform the proper scaling. This will work for other like (length to length, volume to volume) unit types. The conversion goes through the base type, so when you write something like ‘set x to 12 as meter’ you create a variable of type meter containing a real number of value 12.0. When you write ‘set y to x as inches’, a coercion handler will perform any scaling needed to convert from meters to inches, which essentially means that it will multiply the meters value of 12 by 39.0625. If you then write ‘set z to y as feet’, the inches value in y is converted back to meters, then scaled as needed to get the number of feet in 12 meters… The biggest limitation to the current scheme is that it is up to the script writer to make sure that different unit types are of the same base before using them in calculation. It makes script writing a bit cumbersome, but it was felt that the benefits outweighed the limitations. 10/10/99

Unicode text is said to be fully supported. Technote 1142 suggests this means only that the class ‘Unicode text’ is recognized as a stream of Unicode text, which can be coerced to and from the ‘text’, ‘styled text’ and ‘international text’ classes. For example, the AppleScript statement ‘Bill as Unicode text’ returns the value ‘<<data utxt00420069006C006C>>’. The statement ‘class of <<data utxt00420069006C006C>>’ returns Unicode text. And the statement ‘<<data utxt00420069006C006C>> as text’ returns Bill. A Unicode-savvy application like Style, the scriptable text processor by Marco Piovanelli, inserts the word Bill into a document when you run this statement: ‘tell application Style to set beginning of front document to <<data utxt00420069006C006C>>’. Marco has described his discoveries regarding Unicode in AppleScript as follows: While exploring the new Unicode capabilities in Allegro, I stumbled into this definition: typeStyledUnicodeText = FOUR_CHAR_CODE(‘sutx’) (from version 3.2 of <AERegistry.h>). Interesting. Let’s see if AppleScript understands this. In the Script Editor, the following line: <> compiles to: styled Unicode text So ‘sutx’ was added to the 8.5 global aeut. Unfortunately, there doesn’t seem to be a systemwide coercion handler from STXT (styled text) to sutx, while there is a coercion handler from TEXT to utxt (Unicode text). (BTW, you can list system coercion handlers using my aeinfo dcmd). Too bad. I imagine a ‘sutx’ descriptor is analogous to a ‘STXT’ descriptor, i.e., a coerced AE record with keys keyAEText (or its equivalent for Unicode) and keyAEStyles. Marco’s findings are confirmed in the AppleScript 1.3.4 SDK. 10/10/99

Folder actions are implemented, as a first step toward making the Finder attachable.

On the negative side, only the English scripting dialect is supported in AppleScript 1.3.

In Mac OS 8.5, you can use an idle handler to check when a file copy has completed. From Andy Bachorski of Apple: For the case where the Finder is copying a file, you can check the file type and creator type of the file you are interested in. While the Finder is copying a file, it will have a creator code of ‘MACS’ and a file type of 'bzy ’ [Note the space after ‘bzy’]. You would write your script to wait until the file no longer has these codes to know when the copy is finished. For an example of how to implement this feature using an idle handler, see the Wait for Copy script. 10/10/99

The Finder also implements a new ‘as alias list’ coercion, designed to let you obtain very rapidly a list of aliases to Finder items meeting scripted criteria, in addition to the list of Finder references that has heretofore been available. Jon Pugh objects to this new construct because it is not a generalized solution to the problem of how to get a list of aliases. Paraphrasing Jon in an October 3, 1998 communication to the MacScripting mailing list, The original problem was this:

tell application "Finder"
	set x to items of folder foo as alias
end tell

The workaround is this (we’ll skip the tell block from here on):

	set x to items of folder foo as alias
	  on error number -1700 from y      
		set x to y   
end try

Now, the kludge is this:

	set x to items of folder foo as alias list

So, what happens if you do this?

	set x to items of folder foo as string

There isn’t a string list, so you still need to use the old workaround and the problem isn’t really fixed. It’s just got a band-aid on it. 10/10/99

With Mac OS 8.5, Apple has published a number of scripts that cleverly make Apple’s Script Editor scriptable after a fashion. They belong in a Script Editor subfolder in the Scripts folder, so that OSA Menu or OSA Menu Lite will list them in the Scripts menu when the Script Editor is frontmost. On October 19, 1998, Jon Pugh suggested another trick, making it easy to open frequently-used terminology dictionaries from OSA Menu. Put this script in a Script Editor subfolder in the Scripts folder in your System Folder:

	property a : alias Macintosh HD:System Folder:Finder

tell application "Script Editor"
	open a
end	tell

Then do the same for all of your scriptable applications. To make the task easier, write a Finder script that gets the selection as an alias, copies the script above to a new file based on the alias file name, loads the script, sets property a to the alias and stores the script back. This will allow you to create new custom dictionary opening scripts from the Finder. 10/10/99