10.9 Changes

This article describes changes to AppleScript and related tools in OS X Mavericks v10.9.

Enhancements

AppleScript

Script Libraries: You can now use a script as a script library, and use the handlers and properties it defines from any other script, making it dramatically easier to reuse code. Libraries may also use AppleScript/Objective-C and define their own terminology.

“use” Statements: Scripts can now explicitly declare what other code they use, such as applications or script libraries. use statements can also import terminology for use throughout a script without explicit tell statements, simplifying script structure.

Notifications: Scripts can now post notifications using the new display notification command in Standard Additions.

Interleaved Argument Syntax: AppleScript now supports an interleaved-argument syntax for handlers which can make positional-argument handlers easier to read: for example, on doThis:a withThat:b defines a handler with two parameters, a and b. The interleaved syntax may be used in any script, but is especially useful for calling Objective-C methods with AppleScriptObjC. In a compiled script, AppleScript will automatically translate the old positional form with underscores (such as its doThis_withThat_(a, b)) to the interleaved form (its doThis:a withThat:b), and the interleaved form will appear as the old positional form if opened on an older system.

For more details on new AppleScript language features, see the AppleScript Language Guide.

AppleScript Editor

Documents in the Cloud: AppleScript Editor now supports saving script documents to iCloud; any such documents will be automatically synchronized between all computers sharing the same iCloud account.

Code Signing: AppleScript Editor’s Export… command can now sign exported files with your Developer Identity. This takes the place of the procedure described in the 10.8 notes under Gatekeeper and Signing Applets.

Bug Fixes

The default formatting of enumerated values has changed to make them more visually distinct from properties. [6778154]

osascript(1) is now a “UI element” process and can therefore display its own UI, such as using display dialog; telling another application such as System Events is no longer necessary. [12365409]

Getting the last word of a string no longer leaks memory. [12959927]

Negating a numeric string such as "4.1" now produces the correct result. [13599507]

Compatibility Notes

Accessibility

Accessibility features in OS X Mavericks, including System Events’ Processes suite, no longer have a single switch to enable or disable them system-wide (the “Enable access for assistive devices” checkbox). Applications must now be individually authorized to use Accessibility using the Security & Privacy preference pane in System Preferences. If an unauthorized application attempts to use Accessibility, it will fail. The system will present a dialog directing the user to the appropriate place in System Preferences; once approved, the previously denied feature will work.

System Events attributes all uses of Accessibility features to the application calling it, so if an AppleScript applet uses, for example, UI elements, the applet must be authorized, not System Events. System Events’ UI elements enabled property and AppleScript Utility’s GUI Scripting enabled property are still available, but are now read-only, and will tell you if the caller is authorized to use Accessibility.

Applets that use Accessibility features will not save their properties when run. This is because of how the system tracks which applications are authorized: applets that save their properties modify their own contents to do so, which makes them look to the system like a different application that must be re-authorized. If you have an applet that requires both Accessibility and persistent property values, you can specially sign it such that it will still work without needing constant re-authorization; see http://support.apple.com/kb/HT5914 for details.

Developer Notes

Scriptable Applications

The value of the OSAScriptingDefinition Info.plist key may now be the base name of the sdef file; the “.sdef” extension is no longer required. [12909256]

Sandboxed applications can now compile scripts that target other applications even if the target application is not in /Applications. Your application will need an appropriate entitlement to compile and execute the script. [13042006]

Scripting Additions

In scripts that use use scripting additions, AppleScript can optimize Apple event sending for some scripting addition commands, automatically eliminating the double-send described in Scripting Addition Security. Currently, it can perform this optimization for any scripting addition command with a Context value of Any in its Info.plist definition: for Standard Additions, this covers ASCII character, ASCII number, offset, random number, and round. This optimization is expected to cover more cases in the future; for best performance, make sure that your scripting addition has the strictest context possible. For more details on writing scripting additions and the meaning of the different context values, see Tech Note 1164, Scripting Additions for Mac OS X.

Libraries

To debug library and framework loading, define the environment variable ASDebugLibraryLoads. AppleScript will then log whenever it loads a script library or framework:

AppleScript Editor[70986] <Notice>: AppleScript loaded library into component 0x810011: /Users/somebody/Library/Script Libraries/Map Window.scptd
AppleScript Editor[70986] <Notice>: AppleScript loaded framework for component 0x810012 OSAID(3): /System/Library/Frameworks/AppKit.framework
AppleScript Editor[70986] <Notice>: AppleScript referenced loaded framework for component 0x820011 OSAID(1): /System/Library/Frameworks/AppKit.framework

These messages are logged to the ASL facility com.apple.AppleScript.

10.9.2 Changes

Scripts running in AppleScript Editor, Script Menu, script applets, and osascript(1) are now exempt from App Nap, and should no longer slow down when not running in the frontmost application. Third-party applications that run scripts in-process are still eligible for App Nap. [1560184, 1560275]

Dialogs in script applets now work correctly with Accessibility tools such as VoiceOver. [15328639]

Basic editing commands (Cut, Paste, etc.) now work correctly in dialogs run from Script Menu. [15650250]

do shell script with administrator privileges is no longer limited to 255 calls in a single script. [15620418]

System Events’ make new property list item command now works correctly when creating a list or record. [15212879]

10.9.3 Changes

System Events will no longer trigger an Accessibility access dialog when attempting to use a process object that does not exist. [16166963]

10.9.2 would not background tasks run with do shell script with administrator privileges and would always wait until the task exited; this now works correctly again. [16213937]