Brati's Lover · AppleScript

AppleScript Library

    A collection of AppleScript libraries to make up for missing standard functionality. Currently the following libraries are available:

Display Library
Retrieve some information on the connected displays.
Files & Folders Library
Reading/writing data, renaming files, color labels of files and folders, getting information on files and folders.
iWork Numbers Library
Some handlers to facilitate scripting iWork Numbers.
iWork Pages Library
This library contains AppleScript handlers for working with iWork's Pages.
Keychain Library
Some handlers to facilitate the access to logins and passwords stored in Mac OS keychains via AppleScript.
List Library
A bunch of handy functions to manipulate and analyze AppleScript lists.
Number Library
Some useful handlers for working with numbers in AppleScript.
Property List Library
Create, read from, write to and add keys to property list files.
String Library
The string library holds a collection of handlers for string manipulation (counting, finding, replacing, splitting,... ).
Time Machine Library
Some handlers to get information on Mac OS X's built in Time Machine and trigger a Time Machine backup.
URL Library
Two simple handlers to decode and encode URLs.

Using AppleScript Libraries

    There are different ways libraries can be used to speed up scripting with AppleScript. This website provides some libraries for common everyday problems. Libraries can easily be included into your script.

This example will use the replaceString handler of the String Library. First download the entire library, unzip the archive and move the extracted file '_script.scpt' to the desktop. If you want, open the scpt-file in AppleScript-Editor. It contains the same information as shown on the String Library website.

Next, open a new empty document in AppleScript Editor. Loading an AppleScript library is easy:

set _string to load script alias ((path to desktop as text) & "_string.scpt")

The string library is now ready for use. There are various ways of calling a handler within a library. To demonstrate them, let's introduce some silly string:

set str to "This is a test!"

Personally, I prefer and recommend the 'genitiv'-like syntax since it doesn't require a whole lot of code:

set resultOne to _string's replaceString(str, "test", "cat") --> "This is a cat!"

The second alternative is using the 'genitiv'-like syntax with the 'of'-keyword:

set resultTwo to replaceString(str, "test", "dog") of _string --> "This is a dog!"

Last but not least you may also use the well-known 'tell'-syntax. In my opinion, this is not a good way since it requires too much additional unnecessary code:

tell _string
        set resultThree to replaceString(str, "test", "monkey") --> "This is a monkey!"
end tell

tell _string to set resultFour to replaceString(str, "test", "rat") --> "This is a rat!"

That's it! That's pretty much all you need to know to work with AppleScript libraries.

You can download this short example or open it directly in AppleScript Editor.

Credits

    Obviously not all of the functions and handlers found on this site were written by myself. Credits go out to the following websites:

HAS | appleMods
Aurelio.net
hohabadu.de
Mac OS X Automation
Piero Garzotto