objc-appscript

PreviousUpNext appscript / aem

9. Reference Forms

Property reference

A property either contains a simple value or represents a one-to-one relationship between two application objects. Properties either describe the application object (its name, class, size, color, preferences, etc.) or provide a convenient reference to other object(s) of interest to users (e.g. home, currentTrack).

Syntax:

[reference property]

Examples:

[textedit name]
[[[textedit documents] at: 1] text]
[[[finder home] files] name]

Element references

Elements represent a one-to-many relationship between application objects. Elements usually reflect the containment structure of the application object model and generally provide multiple ways of referencing some or all of those objects (e.g. characters/words/paragraphs of documents by index/relative-position/range/filter).

All Elements

Syntax:

[reference elements]

Examples:

[[finder home] folders]
[textedit windows]
[[[textedit documents] paragraphs] words]

by Name

Syntax:

[elements byName: selector]
 selector = NSString -- name of object (as matches its 'name' property)

Examples:

[disks byName: @"Macintosh HD"]
[files byName: @"index.html"]

Note: applications usually treat object names as case-insensitive. Where multiple element have the same name, a by-name reference only identifies the first element found with that name. (Tip: to identify all elements with a particular name, use a by-test reference instead.)

by Index

Syntax:

[elements byIndex: selector]
 selector = NSNumber -- index of object
[elements at: selector]
 selector = int -- index of object

Examples:

[words byIndex: [NSNumber numberWithInt: 3]]
[items at: -1]

Note: elements are one-indexed (AEM-style indexing), not zero-indexed (Ruby-style indexing).

Note that while element indexes are usually integers, some applications may accept other types (e.g. Finder accepts aliases in filesystem references).

by ID

Syntax:

[elements byID: selector]
 selector = anything -- object's id

Examples:

[windows byID: 4321]

by Absolute Position

Syntax:

[elements first] -- first element
[elements middle] -- middle element
[elements last] -- last element
[elements any] -- random element

Examples:

[documents first]
[paragraphs last]
[files any]

by Relative Position

Syntax:

[element previous: className] -- nearest element of a given class to appear 
 before the specified element
[element next: className] -- nearest element of a given class to appear 
 after the specified element
 className = ASConstant -- class of element
 (see Classes and Enumerated Types)

Examples:

[[words at: 3] next: [TEConstant word]]
[[paragraphs at: -1] previous: [TEConstant character]]

by Range

Range references select all elements between and including two references indicating the start and end of the range. The start and end references are normally declared relative to the container of the elements being selected. These references are constructed using a glue-defined 'Con' macro, e.g. TECon, as their root. For example, to indicate the third paragraph of the currrent container object:

[[TECon paragraphs] at: 3]

For convenience, the -byRange: method also allows start and end references to be written in shorthand form where their element class is the same as the elements being selected; thus:

[[ref paragraphs] byRange: [[TECon paragraphs] at: 3]
 [[TECon paragraphs] at: -1]]

can also be written as:

[[ref paragraphs] byRange: [[NSNumber numberWithInt: 3]
 to: [[NSNumber numberWithInt: -1]]

Where start and end points are both indexes (the most common form), this can be shortened even further by using the -at:to: convenience method:

[[ref paragraphs] at: 3 to: -1]

Some applications can handle more complex range references. For example, the following will work in Tex-Edit Plus:

[[ref words] byRange: [[TEPCon characters] at: 5]
 to: [[TEPCon paragraphs] at: -2]]

Syntax:

[elements byRange: start to: end]
 start = NSNumber | NSString | ASReference -- start of range
 end = NSNumber | NSString | ASReference -- end of range
[elements at: start to: end]
 start = int -- start of range
 end = int -- end of range

Examples:

[folders byRange: @"Documents" to: @"Movies"]
[documents at: 1 to: 3]
[text byRange: [[TEPCon characters] at: 5]
 to: [[TEPCon words] at: -2]]

by Test

A reference to each element that satisfies one or more conditions specified by a test expression:

[elements byTest: testExpression]

Test expressions consist of the following:

Insertion location

Insertion locations can be specified at the beginning or end of all elements, or before or after a specified element or element range.

Syntax:

[elements beginning]
[elements end]
[element before]
[element after]

Examples:

[documents end]
[[paragraphs at: 1] before]
PreviousUpNext

AltStyle によって変換されたページ (->オリジナル) /