13.16. The with transaction Statement

The with transaction statement is a compound statement that enables you to lock communication with an application so that no one else can send commands to the application and potentially foul up the works. This is useful when you are issuing a series of commands to an application to accomplish a certain task. By enclosing those commands inside a with transaction block (which is terminated by an end transaction), you effectively gain exclusive rights to talk to that application. The only caveat is that the application must support this mechanism; how it's implemented is up to the application. The application can implement transactions in a non-exclusive way, as long as it guarantees that no one else can interfere with your transactions. An application may also choose not to support transaction processing at all.

Normally, you would place the with transaction block inside the tell block that talks to the application.

Get Beginning AppleScript® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.