10.10 Changes

This article describes changes to AppleScript and related tools in OS X Yosemite v10.10.

Enhancements

AppleScript

Progress Reporting

AppleScript now has built-in support for reporting progress in a script. The global AppleScript object has four new properties:

  • progress total steps (an integer)

  • progress completed steps (an integer)

  • progress description (text)

  • progress additional description (text)

A script may set any of these properties at any time during the script to update the progress display. progress completed steps divided by progress total steps provides the fraction completed; if completed or total is -1, progress is considered indeterminate. progress description and progress additional description provide a message about what the script is doing.

Exactly how the progress is displayed depends on how the script is run: in Script Editor, it appears in the script window’s status bar; in script applications (applets), it appears as a progress dialog; and for scripts run from Script Menu, it appears in the Script Monitor menu. (Script Monitor appeared in previous system releases, but was only used for Automator workflows; it now displays any script run using NSUserScriptTask, which includes anything run from Script Menu.)

Multi-type Coercion

The as operator can now accept a list of types, instead of a single type. For example, this expression returns x as either an integer or text:

x as {integer, text}

When given a list, the as operator processes the list from the first type to the last, checking if the value is an instance of that type; if one matches, the result is the original value. If none match, then it again processes the list from the first type to the last, attempting to coerce the value to that type; the result is the result of the first successful coercion. If none succeed, it throws an error.

Typed and Optional Parameters

AppleScript handler parameters may now be declared with type specifications by following the formal parameter name with as type|{type…}. For example, you could declare a parameter to be specifically an integer like this:

on frotz(x as integer)

The effect is as if the handler began with set x to x as integer; if coercing the actual value to an integer fails, AppleScript throws an appropriate error, which may be caught with a try block. The type may be a list of types, as described in Multi-type Coercion above.

Labeled parameters may be declared with a default value by following the formal parameter name with :literal. Doing so makes the parameter optional when called. For example, this declares a make handler with a default value for the with data parameter:

on make new theClass with data theData : missing value

This handler can now be called without supplying a with data parameter; the handler would see theData set to the specified default missing value, which it could then test for and handle appropriately.

A parameter may use both a type specification and a default value. For example, this declares a make handler with a with properties parameter that must be a record and has a default value of an empty record:

on make new theClass with properties theProperties as record : {}

AppleScript/Objective-C support

AppleScript/Objective-C is now available to all scripts, not just library scripts. To use an Objective-C framework in your script, you must specify it with a use statement, such as use framework "Foundation".

Script Editor

“AppleScript Editor” is once again named Script Editor, now that AppleScript is no longer the only OSA language included in OS X. See the JavaScript for Automation release notes for details.

The dictionary viewer can now display the dictionary using JavaScript (for JavaScript for Automation) or Objective-C (for Scripting Bridge) syntax.

Other Enhancements

do shell script can now specify a custom prompt to use in the password dialog. [15194980]

Bug Fixes

Referring to a negative out-of-range text item now throws an error instead of returning an empty string. [12467195]

path to … commands and AppleScriptObjC now work normally when used via NSUserScriptTask, such as from Script Menu or a Mail rule. [14271600, 15977267]

Targeting an application by bundle identifier will find an already-running instance of the application, regardless of how the bundle identifier is capitalized. [15309414]

AppleScript now sends an end transaction event when leaving a with transaction block. If the block is exited because of an uncaught error, it sends an abort transaction event first. [16606423]

Developer Notes

Script Editor’s dictionary viewer has been enhanced to provide more-flexible embedded documentation. In particular, you can now cleanly document a set of related sub-items of a large class or a command with many parameters.