DekGenius.com
Team LiB   Previous Section   Next Section
middle

Syntax

get middle folder of startup disk

Description

The middle reference style gets the middle object in a container, including a list. For example, the return value of:

middle item of {"apples","oranges","peaches"}

is "oranges." If there is an even number of items in the container then AppleScript essentially adds one to the count of container items, then uses the div operator to divide the new count by two. For example, to calculate the middle item of {0,1,2,3,4,5,6,7,8,9}, AppleScript adds one to the count of items in this list (making it now 11 items), and then evaluates 11 div 2 to reach 5 (or the fifth item). In this example the middle (or fifth) item evaluates to 4.

AppleScript 1.5 and later has fixed a problem that appeared in AppleScript 1.4.3 and earlier, whereby code that references the middle item of an empty list ("{ }") could crash AppleScript. Now the code (middle item of { }) will compile in AppleScript Version 1.5.5 or 1.6 but raise a runtime error if the code is executed.

    Team LiB   Previous Section   Next Section