AEthereal constructs, sends, and receives replies from AppleScript-compatible AppleEvents. "AppleScript-compatible" means that the entire standard AppleEvent Object Model (object and insertion specifiers, etc.) is available and supported.
AEthereal refers to 4-byte AppleEvent codes as "AE4 codes", with Swift type AE4
.
Conversion between Swift objects and AppleEvent descriptors is done through the Swift Codable
interface. Anything Codable
can be sent in an AppleEvent and decoded from a reply. "Unkeyed containers" encode list descriptors; "keyed containers" encode record descriptors. To use custom record keys, use a CodingKeys
enum with AE4
raw type, and conform it to AE4CodingKey
.
private enum CodingKeys: AE4, AE4CodingKey {
// ...
case container = 0x66726f6d
// ...
}
Keys that are well-known event attribute codes are encoded as such.
To enforce use of a non-default descriptor type code, conform your type to AETyped
.
struct ObjectSpecifier: AETyped {
// ...
public var aeType: AE4.AEType {
.objectSpecifier
}
// ...
}
AppleEvent send functions will encode attributes and parameters for you, but if you still want to manually encode something, use AEEncoder
. AppleEvent send functions do not decode anything other than errors, so if you have to read the reply data, use AEDecoder
.
Beginning at a RootSpecifier
, chain calls to any of these methods to build queries:
byProperty(_:)
— property object specifierbyUserProperty(_:)
— AppleScript "user property" object specifierbyIndex(_:_:)
— by-index object specifierbyAbsolute(_:_:)
— absolute position (first, last, middle, random, all) object specifierbyRelative(_:_:)
— relative position (before/previous, after/next) object specifierbyName(_:_:)
— by-name object specifierbyID(_:_:)
— by-ID object specifierbyRange(_:_:)
— by-range object specifierbyTest(_:_:)
— by-test (filter) object specifierinsertion(at:)
— insertion specifier
let nameOfEveryDocument =
RootSpecifier.application
.byAbsolute(AE4.AEType(rawValue: AE4.Classes.document), .all)
.byProperty(AE4.AEType(rawValue: AE4.Properties.name))
Create an App
from an AETarget
and call sendAppleEvent
with an event class/ID pair and any of:
- a target
Query
- event parameters (dictionary from
AE4
to anythingEncodable
) - requested data type (encoded as a parameter)
- "considering/ignoring" flags
- send options and timeout in seconds
If you need a transaction, use withTransaction
.
Parts of AEthereal come from the "dynamic bridge" portion of hhas' SwiftAutomation framework.
hhas has released SwiftAutomation into the public domain. AEthereal uses a dual-licensing approach to retain the spirit of "public domain" while dealing with its often dubious legality.
You may choose one of the following license options:
- AEthereal is released into the public domain, with absolutely no warranty provided.
- AEthereal is released under the terms of the MIT License, a copy of which is provided in LICENSE.txt.