Example AppleScript Libraries
ScriptLibraryIcon-256

AppleScript Libraries are written to extend existing AppleScript functionality, and/or to provide commands “missing” from the default set of AppleScript tools.

Each of the AppleScript Libraries downloadable from this page, are fully editable, and are intended to function as examples and to provide ideas for the creation of your own libraries. Feel free to edit, alter, or expand them to suit your needs.

NOTE:

  1. For instructions on how to install the libraries, refer to the documentation on the Overview page.
  2. When analyzing their scripting dictionaries, refer to the section titled Libraries with Terminology.
  3. Many of the example libraries contain “use” statements. For detail information regarding this new AppleScript construct, refer to the documentation in the Use Statements section.
Viewing a Library’s Dictionary

Viewing the scripting dictionary of an installed AppleScript Library is easy:

To view the scripting dictionary of an installed AppleScript Library, choose Open Dictionary… from the File menu in the AppleScript Editor application. Select the library to view in the list of scriptable resources on your computer, and click the Open button in the dialog.

Using AppleScript Libraries

Once installed, the commands contained in AppleScript Libraries can be accessed by AppleScript scripts using either of two techniques:

  1. Libraries can be addressed directly via tell statements or tell blocks:

    tell script "Sharing Utilities" to tweet text sourceText

  2. A library’s terminology can be imported with a global scope via use statements placed at the top of scripts:

    use script "Sharing Utilities"

    tweet text sourceText

Example: Text Utilities Library

Written using AppleScript/Objective-C, the Text Utilities library contains terminology for three commands designed to perform common text manipulation tasks:

  1. transform text sourceText to upper case | lower case | word case

  2. replace text searchString with replacementString in sourceText

  3. remove white space around sourceText

DOWNLOAD: Text Utilities library

Example: Sharing Utilities Library

Written using AppleScript/Objective-C, the Sharing Utilities library contains terminology for three sharing commands that implement OS X’s native sharing services. The first two are designed to Tweet using the current user’s default Twitter account:

  1. tweet text sourceText

  2. tweet image imageFile with text sourceText

The third command is for beginning an AirDrop session containing one or more disk items:

  1. begin AirDrop with theseItems

DOWNLOAD: Sharing Utilities library (v1.1 updated 5-30-14)

Example: WebKit Utilities Library

Written using AppleScript/Objective-C, the Text Utilities library contains terminology for a single command designed to display the contents of a URL in a created web viewer window:

  1. display URL targetURL window size widthHeightList

IMPORTANT: Because the WebKit Utilities library draws windows using Cococa framework methods, it must be called from Cocoa-AppleScript applets (ASOC) instead of standard AppleScript Applets, in order to display windows correctly. Cocoa-AppleScript applets can created via the New from Template menu item in the File menu in the AppleScript Editor application.

DOWNLOAD: WebKit Utilities libraryWebKit Utilities library and Example ASOC applet

Example: Alert Utilities Library

The Alert Utilities library is an example of using an AppleScript Library to provide an AppleScript terminology interface to a UNIX command-line utility. View the library’s dictionary for more example scripts and detail.

Click magnifying glass icon to view dictionary:

NOTE: This AppleScript Library incorporates the infamous BigHonkingText UNIX utility. Used with permission.

The script shown below will display a text message overlaid on the computer screen:

  1. set advancedSettings to {background color:{65535, 0, 0}, background dimensions:{1024, 90}, opacity:100}
    display overlay text "Warning. Boss approaching…" duration 1 advanced settings advancedSettings with goose honk

DOWNLOAD: Alert Utilities library

TOP | CONTINUE