Documentation
¶
Overview ¶
Package scriptingbridge provides Go bindings for the ScriptingBridge framework.
Automate scriptable apps by sending and receiving Apple events.
Scripting Bridge is a technology that lets you control scriptable Apple and third-party applications using standard Objective-C syntax. Introduced in OS X version 10.5 (Leopard), the Scripting Bridge framework dynamically implements an Objective-C bridge to OSA-compliant applications—that is, applications having a scripting interface (usually defined in a `sdef` file). As part of this implementation, it generates Objective-C class implementations of the classes it finds in the scripting interface, including objects and methods representing properties, elements, commands, and so on. The objects are derived from classes defined in the Scripting Bridge framework.
Classes ¶
- SBApplication: The class provides a mechanism enabling an Objective-C program to send Apple events to a scriptable application and receive Apple events in response.
- SBElementArray: is subclass of that manages collections of related objects.
- SBObject: The class declares methods that can be invoked on any object in a scriptable application.
Protocols ¶
- SBApplicationDelegate: This informal protocol defines a delegation method for handling Apple event errors that are sent from a target application to an object.
Key Types ¶
- SBApplication - The SBApplication class provides a mechanism enabling an Objective-C program to send Apple events to a scriptable application and receive Apple events in response.
- SBObject - The SBObject class declares methods that can be invoked on any object in a scriptable application.
- SBElementArray - SBElementArray is subclass of [NSMutableArray] that manages collections of related SBObject objects.
Code generated from Apple documentation. DO NOT EDIT.
Index ¶
- type Class
- type ISBApplication
- type ISBElementArray
- type ISBObject
- type SBApplication
- func NewSBApplication() SBApplication
- func NewSBApplicationWithBundleIdentifier(ident string) SBApplication
- func NewSBApplicationWithData(data objectivec.IObject) SBApplication
- func NewSBApplicationWithElementCodePropertiesData(code coreservices.DescType, properties foundation.INSDictionary, ...) SBApplication
- func NewSBApplicationWithProcessIdentifier(pid int32) SBApplication
- func NewSBApplicationWithProperties(properties foundation.INSDictionary) SBApplication
- func NewSBApplicationWithURL(url foundation.NSURL) SBApplication
- func SBApplicationFromID(id objc.ID) SBApplication
- func (s SBApplication) Activate()
- func (s SBApplication) Autorelease() SBApplication
- func (s SBApplication) ClassForScriptingClass(className string) objectivec.Class
- func (s SBApplication) Delegate() SBApplicationDelegate
- func (s SBApplication) Init() SBApplication
- func (s SBApplication) InitWithBundleIdentifier(ident string) SBApplication
- func (s SBApplication) InitWithProcessIdentifier(pid int32) SBApplication
- func (s SBApplication) InitWithURL(url foundation.NSURL) SBApplication
- func (s SBApplication) IsRunning() bool
- func (s SBApplication) LaunchFlags() uint32
- func (s SBApplication) SendMode() coreservices.AESendMode
- func (s SBApplication) SetDelegate(value SBApplicationDelegate)
- func (s SBApplication) SetLaunchFlags(value uint32)
- func (s SBApplication) SetSendMode(value coreservices.AESendMode)
- func (s SBApplication) SetTimeout(value int)
- func (s SBApplication) Timeout() int
- type SBApplicationClass
- type SBApplicationDelegate
- type SBApplicationDelegateObject
- type SBElementArray
- func (s SBElementArray) ArrayByApplyingSelector(selector objc.SEL) []objectivec.IObject
- func (s SBElementArray) ArrayByApplyingSelectorWithObject(aSelector objc.SEL, argument objectivec.IObject) []objectivec.IObject
- func (s SBElementArray) Autorelease() SBElementArray
- func (s SBElementArray) Get() []objectivec.IObject
- func (s SBElementArray) Init() SBElementArray
- func (s SBElementArray) ObjectAtLocation(location objectivec.IObject) objectivec.IObject
- func (s SBElementArray) ObjectWithID(identifier objectivec.IObject) objectivec.IObject
- func (s SBElementArray) ObjectWithName(name string) objectivec.IObject
- type SBElementArrayClass
- type SBObject
- func NewSBObject() SBObject
- func NewSBObjectWithData(data objectivec.IObject) SBObject
- func NewSBObjectWithElementCodePropertiesData(code coreservices.DescType, properties foundation.INSDictionary, ...) SBObject
- func NewSBObjectWithProperties(properties foundation.INSDictionary) SBObject
- func SBObjectFromID(id objc.ID) SBObject
- func (s SBObject) Autorelease() SBObject
- func (s SBObject) ElementArrayWithCode(code coreservices.DescType) ISBElementArray
- func (s SBObject) EncodeWithCoder(coder foundation.INSCoder)
- func (s SBObject) Get() objectivec.IObject
- func (s SBObject) Init() SBObject
- func (s SBObject) InitWithData(data objectivec.IObject) SBObject
- func (s SBObject) InitWithElementCodePropertiesData(code coreservices.DescType, properties foundation.INSDictionary, ...) SBObject
- func (s SBObject) InitWithProperties(properties foundation.INSDictionary) SBObject
- func (s SBObject) LastError() foundation.NSError
- func (s SBObject) PropertyWithClassCode(cls objectivec.Class, code coreservices.AEKeyword) ISBObject
- func (s SBObject) PropertyWithCode(code coreservices.AEKeyword) ISBObject
- func (s SBObject) SetTo(value objectivec.IObject)
- type SBObjectClass
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ISBApplication ¶
type ISBApplication interface {
ISBObject
// Returns an instance of an [SBApplication] subclass that represents the target application identified by the given bundle identifier.
InitWithBundleIdentifier(ident string) SBApplication
// Returns an instance of an [SBApplication] subclass that represents the target application identified by the given process identifier.
InitWithProcessIdentifier(pid int32) SBApplication
// Returns an instance of an [SBApplication] subclass that represents the target application identified by the given URL.
InitWithURL(url foundation.NSURL) SBApplication
// Returns a class object that represents a particular class in the target application.
ClassForScriptingClass(className string) objectivec.Class
// Moves the target application to the foreground immediately.
Activate()
// A Boolean that indicates whether the target application represented by the receiver is running.
IsRunning() bool
// The launch flags for the application represented by the receiver.
LaunchFlags() uint32
SetLaunchFlags(value uint32)
// The mode for sending Apple events to the target application.
SendMode() coreservices.AESendMode
SetSendMode(value coreservices.AESendMode)
// The period the application will wait to receive reply Apple events.
Timeout() int
SetTimeout(value int)
// The error-handling delegate of the receiver.
Delegate() SBApplicationDelegate
SetDelegate(value SBApplicationDelegate)
}
An interface definition for the SBApplication class.
Initializing a Scriptable Application Object ¶
- ISBApplication.InitWithBundleIdentifier: Returns an instance of an SBApplication subclass that represents the target application identified by the given bundle identifier.
- ISBApplication.InitWithProcessIdentifier: Returns an instance of an SBApplication subclass that represents the target application identified by the given process identifier.
- ISBApplication.InitWithURL: Returns an instance of an SBApplication subclass that represents the target application identified by the given URL.
Creating a Scripting Class ¶
- ISBApplication.ClassForScriptingClass: Returns a class object that represents a particular class in the target application.
Controlling the Application ¶
- ISBApplication.Activate: Moves the target application to the foreground immediately.
- ISBApplication.IsRunning: A Boolean that indicates whether the target application represented by the receiver is running.
- ISBApplication.LaunchFlags: The launch flags for the application represented by the receiver.
- ISBApplication.SetLaunchFlags
- ISBApplication.SendMode: The mode for sending Apple events to the target application.
- ISBApplication.SetSendMode
- ISBApplication.Timeout: The period the application will wait to receive reply Apple events.
- ISBApplication.SetTimeout
Managing the Delegate ¶
- ISBApplication.Delegate: The error-handling delegate of the receiver.
- ISBApplication.SetDelegate
See: https://developer.apple.com/documentation/ScriptingBridge/SBApplication
type ISBElementArray ¶
type ISBElementArray interface {
foundation.INSMutableArray
// Returns the object in the array with the given name.
ObjectWithName(name string) objectivec.IObject
// Returns the object in the array with the given identifier.
ObjectWithID(identifier objectivec.IObject) objectivec.IObject
// Returns the object at the given location in the receiver.
ObjectAtLocation(location objectivec.IObject) objectivec.IObject
// Forces evaluation of the receiver, causing the real object to be returned immediately.
Get() []objectivec.IObject
// Returns an array containing the results of sending the specified message to each object in the receiver.
ArrayByApplyingSelector(selector objc.SEL) []objectivec.IObject
// Returns an array containing the results of sending the specified message to each object in the receiver.
ArrayByApplyingSelectorWithObject(aSelector objc.SEL, argument objectivec.IObject) []objectivec.IObject
}
An interface definition for the SBElementArray class.
Getting Objects in the Array ¶
- ISBElementArray.ObjectWithName: Returns the object in the array with the given name.
- ISBElementArray.ObjectWithID: Returns the object in the array with the given identifier.
- ISBElementArray.ObjectAtLocation: Returns the object at the given location in the receiver.
Getting the Referenced Array ¶
- ISBElementArray.Get: Forces evaluation of the receiver, causing the real object to be returned immediately.
Filtering an Element Array ¶
- ISBElementArray.ArrayByApplyingSelector: Returns an array containing the results of sending the specified message to each object in the receiver.
- ISBElementArray.ArrayByApplyingSelectorWithObject: Returns an array containing the results of sending the specified message to each object in the receiver.
See: https://developer.apple.com/documentation/ScriptingBridge/SBElementArray
type ISBObject ¶
type ISBObject interface {
objectivec.IObject
// Returns an instance of an [SBObject] subclass initialized with the given data.
InitWithData(data objectivec.IObject) SBObject
// Returns an instance of an [SBObject] subclass initialized with the specified properties.
InitWithProperties(properties foundation.INSDictionary) SBObject
// Returns an instance of an [SBObject] subclass initialized with the specified properties and data and added to the designated element array.
InitWithElementCodePropertiesData(code coreservices.DescType, properties foundation.INSDictionary, data objectivec.IObject) SBObject
// Forces evaluation of the receiver, causing the real object to be returned immediately.
Get() objectivec.IObject
// Sets the receiver to a specified value.
SetTo(value objectivec.IObject)
// Returns an object of the designated scripting class representing the specified property of the receiver
PropertyWithClassCode(cls objectivec.Class, code coreservices.AEKeyword) ISBObject
// Returns an object representing the specified property of the receiver.
PropertyWithCode(code coreservices.AEKeyword) ISBObject
// Returns an array containing every child of the receiver with the given class-type code.
ElementArrayWithCode(code coreservices.DescType) ISBElementArray
// The error from the last event this object sent, or nil if it succeeded.
LastError() foundation.NSError
EncodeWithCoder(coder foundation.INSCoder)
}
An interface definition for the SBObject class.
Initializing a Scripting Bridge Object ¶
- ISBObject.InitWithData: Returns an instance of an SBObject subclass initialized with the given data.
- ISBObject.InitWithProperties: Returns an instance of an SBObject subclass initialized with the specified properties.
- ISBObject.InitWithElementCodePropertiesData: Returns an instance of an SBObject subclass initialized with the specified properties and data and added to the designated element array.
Getting Referenced Data ¶
- ISBObject.Get: Forces evaluation of the receiver, causing the real object to be returned immediately.
Sending Apple Events ¶
- ISBObject.SetTo: Sets the receiver to a specified value.
Getting Properties and Elements ¶
- ISBObject.PropertyWithClassCode: Returns an object of the designated scripting class representing the specified property of the receiver
- ISBObject.PropertyWithCode: Returns an object representing the specified property of the receiver.
- ISBObject.ElementArrayWithCode: Returns an array containing every child of the receiver with the given class-type code.
Instance Methods ¶
- ISBObject.LastError: The error from the last event this object sent, or nil if it succeeded.
See: https://developer.apple.com/documentation/ScriptingBridge/SBObject
type SBApplication ¶
type SBApplication struct {
SBObject
}
The SBApplication class provides a mechanism enabling an Objective-C program to send Apple events to a scriptable application and receive Apple events in response. It thereby makes it possible for that program to control the application and exchange data with it. Scripting Bridge works by bridging data types between Apple event descriptors and Cocoa objects.
Overview ¶
Although SBApplication includes methods that manually send and process Apple events, you should never have to call these methods directly. Instead, subclasses of SBApplication implement application-specific methods that handle the sending of Apple events automatically.
For example, if you wanted to get the current iTunes track, you can simply use the `currentTrack` method of the dynamically defined subclass for the iTunes application—which handles the details of sending the Apple event for you—rather than figuring out the more complicated, low-level alternative:
If you do need to send Apple events manually, consider using the [NSAppleEventDescriptor] class.
Subclassing Notes ¶
You rarely instantiate SBApplication objects directly. Instead, you get the shared instance of a application-specific subclass typically by calling one of the `applicationWith...` class methods, using a bundle identifier, process identifier, or URL to identify the application.
Initializing a Scriptable Application Object ¶
- SBApplication.InitWithBundleIdentifier: Returns an instance of an SBApplication subclass that represents the target application identified by the given bundle identifier.
- SBApplication.InitWithProcessIdentifier: Returns an instance of an SBApplication subclass that represents the target application identified by the given process identifier.
- SBApplication.InitWithURL: Returns an instance of an SBApplication subclass that represents the target application identified by the given URL.
Creating a Scripting Class ¶
- SBApplication.ClassForScriptingClass: Returns a class object that represents a particular class in the target application.
Controlling the Application ¶
- SBApplication.Activate: Moves the target application to the foreground immediately.
- SBApplication.IsRunning: A Boolean that indicates whether the target application represented by the receiver is running.
- SBApplication.LaunchFlags: The launch flags for the application represented by the receiver.
- SBApplication.SetLaunchFlags
- SBApplication.SendMode: The mode for sending Apple events to the target application.
- SBApplication.SetSendMode
- SBApplication.Timeout: The period the application will wait to receive reply Apple events.
- SBApplication.SetTimeout
Managing the Delegate ¶
- SBApplication.Delegate: The error-handling delegate of the receiver.
- SBApplication.SetDelegate
See: https://developer.apple.com/documentation/ScriptingBridge/SBApplication
func NewSBApplication ¶
func NewSBApplication() SBApplication
NewSBApplication creates a new SBApplication instance.
func NewSBApplicationWithBundleIdentifier ¶
func NewSBApplicationWithBundleIdentifier(ident string) SBApplication
Returns an instance of an SBApplication subclass that represents the target application identified by the given bundle identifier.
ident: A bundle identifier specifying an application that is OSA-compliant.
Return Value ¶
An initialized shared instance of an SBApplication subclass that represents a target application with the bundle identifier of `ident`. Returns `nil` if no such application can be found or if the application does not have a scripting interface.
Discussion ¶
If you must initialize an SBApplication object explictly, you should use this initializer if possible; unlike SBApplication.InitWithProcessIdentifier and SBApplication.InitWithURL, this method is not dependent on changeable factors such as the target application’s path or process ID. Even so, you should rarely have to initialize an SBApplication object yourself; instead, you should initialize an application-specific subclass such as `iTunesApplication`.
Note that this method does not check whether an application with the given bundle identifier actually exists.
See: https://developer.apple.com/documentation/ScriptingBridge/SBApplication/init(bundleIdentifier:)
func NewSBApplicationWithData ¶
func NewSBApplicationWithData(data objectivec.IObject) SBApplication
Returns an instance of an SBObject subclass initialized with the given data.
data: An object containing data for the new SBObject object. The data varies according to the type of scripting object to be created.
Return Value ¶
An SBObject object or `nil` if the object could not be initialized.
Discussion ¶
Scripting Bridge does not actually create an object in the target application until you add the object returned from this method to an element array (SBElementArray).
See: https://developer.apple.com/documentation/ScriptingBridge/SBObject/init(data:)
func NewSBApplicationWithElementCodePropertiesData ¶
func NewSBApplicationWithElementCodePropertiesData(code coreservices.DescType, properties foundation.INSDictionary, data objectivec.IObject) SBApplication
Returns an instance of an SBObject subclass initialized with the specified properties and data and added to the designated element array.
code: A four-character code used to identify an element in the target application’s scripting interface. See Apple Event Manager for details.
properties: A dictionary with NSNumber keys specifying the four-character codes of properties (that is, attributes or to-one relationships) and the values for those properties. Pass `nil` if you are initializing the object by `data` only.
data: An object containing data for the new SBObject object. The data varies according to the type of scripting object to be created. Pass `nil` if you initializing the object by `properties` only.
Return Value ¶
An SBObject object or `nil` if the object could not be initialized.
Discussion ¶
Unlike the other initializers of this class, this method not only initializes the SBObject object but adds it to a specified element array. This method is the designated initializer.
func NewSBApplicationWithProcessIdentifier ¶
func NewSBApplicationWithProcessIdentifier(pid int32) SBApplication
Returns an instance of an SBApplication subclass that represents the target application identified by the given process identifier.
pid: A BSD process ID specifying an application that is OSA-compliant. Often you can get the process ID of a process using the processIdentifier method of [NSTask].
Return Value ¶
An initialized SBApplication that you can use to communicate with the target application specified by the process ID. Returns `nil` if no such application can be found or if the application does not have a scripting interface.
Discussion ¶
You should avoid using this method unless you know nothing about an external application but its PID. In most cases, it is better to use SBApplication.InitWithBundleIdentifier, which will dynamically locate the external application’s path at runtime, or SBApplication.InitWithURL, which is not dependent on the external application being open at the time the method is called.
See: https://developer.apple.com/documentation/ScriptingBridge/SBApplication/init(processIdentifier:)
func NewSBApplicationWithProperties ¶
func NewSBApplicationWithProperties(properties foundation.INSDictionary) SBApplication
Returns an instance of an SBObject subclass initialized with the specified properties.
properties: A dictionary with keys specifying the names of properties (that is, attributes or to-one relationships) and the values for those properties.
Return Value ¶
An SBObject object or `nil` if the object could not be initialized.
Discussion ¶
Scripting Bridge does not actually create an object in the target application until you add the object returned from this method to an element array (SBElementArray).
See: https://developer.apple.com/documentation/ScriptingBridge/SBObject/init(properties:)
func NewSBApplicationWithURL ¶
func NewSBApplicationWithURL(url foundation.NSURL) SBApplication
Returns an instance of an SBApplication subclass that represents the target application identified by the given URL.
url: A Universal Resource Locator (URL) specifying an application that is OSA-compliant.
Return Value ¶
An initialized SBApplication that you can use to communicate with the target application specified by the process ID. Returns `nil` if an application could not be found or if the application does not have a scripting interface.
Discussion ¶
This approach to initializing SBApplication objects should be used only if you know for certain the URL of the target application. In most cases, it is better to use applicationWithBundleIdentifier: which dynamically locates the target application at runtime. Even so, you should rarely have to initialize an SBApplication yourself.
This method currently supports file URLs (“) and remote application URLs (“). It checks whether a file exists at the specified path, but it does not check whether an application identified via “ exists.
See: https://developer.apple.com/documentation/ScriptingBridge/SBApplication/init(url:)
func SBApplicationFromID ¶
func SBApplicationFromID(id objc.ID) SBApplication
SBApplicationFromID constructs a SBApplication from an objc.ID.
The SBApplication class provides a mechanism enabling an Objective-C program to send Apple events to a scriptable application and receive Apple events in response. It thereby makes it possible for that program to control the application and exchange data with it. Scripting Bridge works by bridging data types between Apple event descriptors and Cocoa objects.
func (SBApplication) Activate ¶
func (s SBApplication) Activate()
Moves the target application to the foreground immediately.
Discussion ¶
If the target application is not already running, this method launches it.
See: https://developer.apple.com/documentation/ScriptingBridge/SBApplication/activate()
func (SBApplication) Autorelease ¶
func (s SBApplication) Autorelease() SBApplication
Autorelease adds the receiver to the current autorelease pool.
func (SBApplication) ClassForScriptingClass ¶
func (s SBApplication) ClassForScriptingClass(className string) objectivec.Class
Returns a class object that represents a particular class in the target application.
className: The name of the scripting class, as it appears in the scripting interface. For example, “document”.
Return Value ¶
A Class object representing the scripting class.
Discussion ¶
You invoke this method on an instance of a scriptable application. Once you have the class object, you may allocate an instance of the class and appropriately the raw instance. Or you may use it in a call to isKind(of:) to determine the class type of an object.
See: https://developer.apple.com/documentation/ScriptingBridge/SBApplication/class(forScriptingClass:)
func (SBApplication) Delegate ¶
func (s SBApplication) Delegate() SBApplicationDelegate
The error-handling delegate of the receiver.
Discussion ¶
The delegate should implement the [EventDidFailWithError] method of the SBApplicationDelegate informal protocol.
See: https://developer.apple.com/documentation/ScriptingBridge/SBApplication/delegate
func (SBApplication) Init ¶
func (s SBApplication) Init() SBApplication
Init initializes the instance.
func (SBApplication) InitWithBundleIdentifier ¶
func (s SBApplication) InitWithBundleIdentifier(ident string) SBApplication
Returns an instance of an SBApplication subclass that represents the target application identified by the given bundle identifier.
ident: A bundle identifier specifying an application that is OSA-compliant.
Return Value ¶
An initialized shared instance of an SBApplication subclass that represents a target application with the bundle identifier of `ident`. Returns `nil` if no such application can be found or if the application does not have a scripting interface.
Discussion ¶
If you must initialize an SBApplication object explictly, you should use this initializer if possible; unlike SBApplication.InitWithProcessIdentifier and SBApplication.InitWithURL, this method is not dependent on changeable factors such as the target application’s path or process ID. Even so, you should rarely have to initialize an SBApplication object yourself; instead, you should initialize an application-specific subclass such as `iTunesApplication`.
Note that this method does not check whether an application with the given bundle identifier actually exists.
See: https://developer.apple.com/documentation/ScriptingBridge/SBApplication/init(bundleIdentifier:)
func (SBApplication) InitWithProcessIdentifier ¶
func (s SBApplication) InitWithProcessIdentifier(pid int32) SBApplication
Returns an instance of an SBApplication subclass that represents the target application identified by the given process identifier.
pid: A BSD process ID specifying an application that is OSA-compliant. Often you can get the process ID of a process using the processIdentifier method of [NSTask].
Return Value ¶
An initialized SBApplication that you can use to communicate with the target application specified by the process ID. Returns `nil` if no such application can be found or if the application does not have a scripting interface.
Discussion ¶
You should avoid using this method unless you know nothing about an external application but its PID. In most cases, it is better to use SBApplication.InitWithBundleIdentifier, which will dynamically locate the external application’s path at runtime, or SBApplication.InitWithURL, which is not dependent on the external application being open at the time the method is called.
See: https://developer.apple.com/documentation/ScriptingBridge/SBApplication/init(processIdentifier:)
func (SBApplication) InitWithURL ¶
func (s SBApplication) InitWithURL(url foundation.NSURL) SBApplication
Returns an instance of an SBApplication subclass that represents the target application identified by the given URL.
url: A Universal Resource Locator (URL) specifying an application that is OSA-compliant.
Return Value ¶
An initialized SBApplication that you can use to communicate with the target application specified by the process ID. Returns `nil` if an application could not be found or if the application does not have a scripting interface.
Discussion ¶
This approach to initializing SBApplication objects should be used only if you know for certain the URL of the target application. In most cases, it is better to use applicationWithBundleIdentifier: which dynamically locates the target application at runtime. Even so, you should rarely have to initialize an SBApplication yourself.
This method currently supports file URLs (“) and remote application URLs (“). It checks whether a file exists at the specified path, but it does not check whether an application identified via “ exists.
See: https://developer.apple.com/documentation/ScriptingBridge/SBApplication/init(url:)
func (SBApplication) IsRunning ¶
func (s SBApplication) IsRunning() bool
A Boolean that indicates whether the target application represented by the receiver is running.
Discussion ¶
true if the application is running, false otherwise.
This may be true for instances initialized with a bundle identifier or URL because SBApplication launches the application only when it’s necessary to send it an event.
See: https://developer.apple.com/documentation/ScriptingBridge/SBApplication/isRunning
func (SBApplication) LaunchFlags ¶
func (s SBApplication) LaunchFlags() uint32
The launch flags for the application represented by the receiver.
Discussion ¶
For more information, see Launch Services.
See: https://developer.apple.com/documentation/ScriptingBridge/SBApplication/launchFlags
func (SBApplication) SendMode ¶
func (s SBApplication) SendMode() coreservices.AESendMode
The mode for sending Apple events to the target application.
Discussion ¶
For more information, see Apple Event Manager.
The default send mode is kAEWaitReply. If the send mode is something other than `kAEWaitReply`, the receiver might not correctly handle reply events from the target application.
See: https://developer.apple.com/documentation/ScriptingBridge/SBApplication/sendMode
func (SBApplication) SetDelegate ¶
func (s SBApplication) SetDelegate(value SBApplicationDelegate)
func (SBApplication) SetLaunchFlags ¶
func (s SBApplication) SetLaunchFlags(value uint32)
func (SBApplication) SetSendMode ¶
func (s SBApplication) SetSendMode(value coreservices.AESendMode)
func (SBApplication) SetTimeout ¶
func (s SBApplication) SetTimeout(value int)
func (SBApplication) Timeout ¶
func (s SBApplication) Timeout() int
The period the application will wait to receive reply Apple events.
Discussion ¶
For more information, see Apple Event Manager.
The default timeout value is kAEDefaultTimeout, which is about a minute. If you want the receiver to wait indefinitely for reply Apple events, use kNoTimeOut. For more information, see Apple Event Manager.
See: https://developer.apple.com/documentation/ScriptingBridge/SBApplication/timeout
type SBApplicationClass ¶
type SBApplicationClass struct {
// contains filtered or unexported fields
}
func GetSBApplicationClass ¶
func GetSBApplicationClass() SBApplicationClass
GetSBApplicationClass returns the class object for SBApplication.
func (SBApplicationClass) Alloc ¶
func (sc SBApplicationClass) Alloc() SBApplication
Alloc allocates memory for a new instance of the class.
func (SBApplicationClass) Class ¶
func (sc SBApplicationClass) Class() objc.Class
Class returns the underlying Objective-C class pointer.
type SBApplicationDelegate ¶
type SBApplicationDelegate interface {
objectivec.IObject
// Sent by an [SBApplication] object when a target application returns an error Apple event.
//
// See: https://developer.apple.com/documentation/ScriptingBridge/SBApplicationDelegate/eventDidFail(_:withError:)
EventDidFailWithError(event *coreservices.AEDesc) (objectivec.IObject, error)
}
This informal protocol defines a delegation method for handling Apple event errors that are sent from a target application to an SBApplication(<https://developer.apple.com/documentation/ScriptingBridge/SBApplication>) object.
See: https://developer.apple.com/documentation/ScriptingBridge/SBApplicationDelegate
type SBApplicationDelegateObject ¶
type SBApplicationDelegateObject struct {
objectivec.Object
}
SBApplicationDelegateObject wraps an existing Objective-C object that conforms to the SBApplicationDelegate protocol.
func SBApplicationDelegateObjectFromID ¶
func SBApplicationDelegateObjectFromID(id objc.ID) SBApplicationDelegateObject
SBApplicationDelegateObjectFromID constructs a SBApplicationDelegateObject from an objc.ID. The object is determined to conform to the protocol at runtime.
func (SBApplicationDelegateObject) BaseObject ¶
func (o SBApplicationDelegateObject) BaseObject() objectivec.Object
func (SBApplicationDelegateObject) EventDidFailWithError ¶
func (o SBApplicationDelegateObject) EventDidFailWithError(event *coreservices.AEDesc) (objectivec.IObject, error)
Sent by an SBApplication object when a target application returns an error Apple event.
event: A pointer to the Apple event sent to the target application causing the error.
error: An object containing information about the error Apple event. Specific information may be included in the `useInfo` dictionary of the error object. The following table shows the possible keys for this dictionary.
[Table data omitted]
Return Value ¶
If you return a result, it will become the result of the sendEvent(_:) that failed. Can be `nil`.
type SBElementArray ¶
type SBElementArray struct {
foundation.NSMutableArray
}
SBElementArray is subclass of [NSMutableArray] that manages collections of related SBObject objects. For example, when you ask the Finder for a list of disks, or ask iTunes for a list of playlists, you get the result back as an SBElementArray containing Scripting Bridge objects representing those items.
Overview ¶
SBElementArray defines methods beyond those of NSArray for obtaining individual objects. In addition to object(at:), SBElementArray also defines SBElementArray.ObjectWithName, SBElementArray.ObjectWithID, and SBElementArray.ObjectAtLocation.
Subclassing Notes ¶
The SBElementArray class is not designed for subclassing.
Getting Objects in the Array ¶
- SBElementArray.ObjectWithName: Returns the object in the array with the given name.
- SBElementArray.ObjectWithID: Returns the object in the array with the given identifier.
- SBElementArray.ObjectAtLocation: Returns the object at the given location in the receiver.
Getting the Referenced Array ¶
- SBElementArray.Get: Forces evaluation of the receiver, causing the real object to be returned immediately.
Filtering an Element Array ¶
- SBElementArray.ArrayByApplyingSelector: Returns an array containing the results of sending the specified message to each object in the receiver.
- SBElementArray.ArrayByApplyingSelectorWithObject: Returns an array containing the results of sending the specified message to each object in the receiver.
See: https://developer.apple.com/documentation/ScriptingBridge/SBElementArray
func NewSBElementArray ¶
func NewSBElementArray() SBElementArray
NewSBElementArray creates a new SBElementArray instance.
func SBElementArrayFromID ¶
func SBElementArrayFromID(id objc.ID) SBElementArray
SBElementArrayFromID constructs a SBElementArray from an objc.ID.
SBElementArray is subclass of [NSMutableArray] that manages collections of related SBObject objects. For example, when you ask the Finder for a list of disks, or ask iTunes for a list of playlists, you get the result back as an SBElementArray containing Scripting Bridge objects representing those items.
func (SBElementArray) ArrayByApplyingSelector ¶
func (s SBElementArray) ArrayByApplyingSelector(selector objc.SEL) []objectivec.IObject
Returns an array containing the results of sending the specified message to each object in the receiver.
selector: A selector identifying the message to be sent to each object in the array.
Return Value ¶
A new array containing the results of sending the `selector` message to each object in the receiver, starting with the first object and continuing through the element array to the last object.
Discussion ¶
The method identified by `selector` must not take any arguments and must return an Objective-C object. It should not have the side effect of modifying the receiving array. The order of the items in the result array corresponds to the order of the items in the original array.
See: https://developer.apple.com/documentation/ScriptingBridge/SBElementArray/array(byApplying:)
func (SBElementArray) ArrayByApplyingSelectorWithObject ¶
func (s SBElementArray) ArrayByApplyingSelectorWithObject(aSelector objc.SEL, argument objectivec.IObject) []objectivec.IObject
Returns an array containing the results of sending the specified message to each object in the receiver.
argument: The value for the parameter of the message identified by `selector`.
Return Value ¶
A new array containing the results of sending the `selector` message to each object in the receiver, starting with the first object and continuing through the element array to the last object.
Discussion ¶
The method identified by `selector` must take a single argument—whose value is provided in `argument`—and must return an object. It should not have the side effect of modifying the receiving array. The order of the items in the result array corresponds to the order of the items in the original array.
See: https://developer.apple.com/documentation/ScriptingBridge/SBElementArray/array(byApplying:with:)
func (SBElementArray) Autorelease ¶
func (s SBElementArray) Autorelease() SBElementArray
Autorelease adds the receiver to the current autorelease pool.
func (SBElementArray) Get ¶
func (s SBElementArray) Get() []objectivec.IObject
Forces evaluation of the receiver, causing the real object to be returned immediately.
Return Value ¶
The object referenced by the receiver.
Discussion ¶
This method forces the evaluation of the current object reference (the receiver), resulting in the return of the referenced object. By default, Scripting Bridge deals with references to objects until you actually request some concrete data from them or until you call the `get` method.
See: https://developer.apple.com/documentation/ScriptingBridge/SBElementArray/get()
func (SBElementArray) Init ¶
func (s SBElementArray) Init() SBElementArray
Init initializes the instance.
func (SBElementArray) ObjectAtLocation ¶
func (s SBElementArray) ObjectAtLocation(location objectivec.IObject) objectivec.IObject
Returns the object at the given location in the receiver.
Return Value ¶
A reference to the SBObject object identified by `loc` or `nil` if the object couldn’t be located.
Discussion ¶
This method is a generalization of object(at:) for applications where the “index” is not simply an integer. For example, Finder can specify objects using a NSURL object as a location. In OSA this is known as “absolute position,” a generalization of the notion of “index” in Foundation—it could be an integer, but it doesn’t have to be. A single object may even have a number of different “absolute position” values depending on the container.
See: https://developer.apple.com/documentation/ScriptingBridge/SBElementArray/object(atLocation:)
func (SBElementArray) ObjectWithID ¶
func (s SBElementArray) ObjectWithID(identifier objectivec.IObject) objectivec.IObject
Returns the object in the array with the given identifier.
identifier: The identifier of one of the receiver’s objects.
Return Value ¶
A reference to the identified object or `nil` if could not be found.
Discussion ¶
This method is provided as an alternative to object(at:) for applications where an identifier is available instead of (or in addition to) an index. A unique ID is generally more stable than an index. For example, it may be more useful to identify a contact in Address Book by its identifier (which doesn’t change over time) than by its index in the list of contacts (which can change as contacts are added or removed).
See: https://developer.apple.com/documentation/ScriptingBridge/SBElementArray/object(withID:)
func (SBElementArray) ObjectWithName ¶
func (s SBElementArray) ObjectWithName(name string) objectivec.IObject
Returns the object in the array with the given name.
name: The name of one of the receiver’s objects.
Return Value ¶
A reference to the designated object or `nil` if the object couldn’t be found.
Discussion ¶
This method is provided as an alternative to object(at:) for applications where a name is available instead of (or in addition to) an index. A name is generally more stable than an index. For example, it is typically more useful to identify a mailbox in Mail by its name than by its index in the list of mailboxes.
See: https://developer.apple.com/documentation/ScriptingBridge/SBElementArray/object(withName:)
type SBElementArrayClass ¶
type SBElementArrayClass struct {
// contains filtered or unexported fields
}
func GetSBElementArrayClass ¶
func GetSBElementArrayClass() SBElementArrayClass
GetSBElementArrayClass returns the class object for SBElementArray.
func (SBElementArrayClass) Alloc ¶
func (sc SBElementArrayClass) Alloc() SBElementArray
Alloc allocates memory for a new instance of the class.
func (SBElementArrayClass) Class ¶
func (sc SBElementArrayClass) Class() objc.Class
Class returns the underlying Objective-C class pointer.
type SBObject ¶
type SBObject struct {
objectivec.Object
}
The SBObject class declares methods that can be invoked on any object in a scriptable application. It defines methods for getting elements and properties of an object, as well as setting a given object to a new value.
Overview ¶
Each SBObject is built around an object specifier, which tells Scripting Bridge how to locate the object. Therefore, you can think of an SBObject as a reference to an object in an target application rather than an object itself. To bypass this reference-based approach and force evaluation, use the SBObject.Get method.
Typically, rather than create SBObject instances explictly, you receive SBObject objects by calling methods of an SBApplication subclass. For example, if you wanted to get an SBObject representing the current iTunes track, you would use code like this (where `iTunesTrack` is a subclass of SBObject):
You can discover the names of dynamically generated classes such as `iTunesApplication` and `iTunesTrack` by examining the header file created by the `sdp` tool. Alternatively, you give these variables the dynamic Objective-C type `id`.
Initializing a Scripting Bridge Object ¶
- SBObject.InitWithData: Returns an instance of an SBObject subclass initialized with the given data.
- SBObject.InitWithProperties: Returns an instance of an SBObject subclass initialized with the specified properties.
- SBObject.InitWithElementCodePropertiesData: Returns an instance of an SBObject subclass initialized with the specified properties and data and added to the designated element array.
Getting Referenced Data ¶
- SBObject.Get: Forces evaluation of the receiver, causing the real object to be returned immediately.
Sending Apple Events ¶
- SBObject.SetTo: Sets the receiver to a specified value.
Getting Properties and Elements ¶
- SBObject.PropertyWithClassCode: Returns an object of the designated scripting class representing the specified property of the receiver
- SBObject.PropertyWithCode: Returns an object representing the specified property of the receiver.
- SBObject.ElementArrayWithCode: Returns an array containing every child of the receiver with the given class-type code.
Instance Methods ¶
- SBObject.LastError: The error from the last event this object sent, or nil if it succeeded.
See: https://developer.apple.com/documentation/ScriptingBridge/SBObject
func NewSBObjectWithData ¶
func NewSBObjectWithData(data objectivec.IObject) SBObject
Returns an instance of an SBObject subclass initialized with the given data.
data: An object containing data for the new SBObject object. The data varies according to the type of scripting object to be created.
Return Value ¶
An SBObject object or `nil` if the object could not be initialized.
Discussion ¶
Scripting Bridge does not actually create an object in the target application until you add the object returned from this method to an element array (SBElementArray).
See: https://developer.apple.com/documentation/ScriptingBridge/SBObject/init(data:)
func NewSBObjectWithElementCodePropertiesData ¶
func NewSBObjectWithElementCodePropertiesData(code coreservices.DescType, properties foundation.INSDictionary, data objectivec.IObject) SBObject
Returns an instance of an SBObject subclass initialized with the specified properties and data and added to the designated element array.
code: A four-character code used to identify an element in the target application’s scripting interface. See Apple Event Manager for details.
properties: A dictionary with NSNumber keys specifying the four-character codes of properties (that is, attributes or to-one relationships) and the values for those properties. Pass `nil` if you are initializing the object by `data` only.
data: An object containing data for the new SBObject object. The data varies according to the type of scripting object to be created. Pass `nil` if you initializing the object by `properties` only.
Return Value ¶
An SBObject object or `nil` if the object could not be initialized.
Discussion ¶
Unlike the other initializers of this class, this method not only initializes the SBObject object but adds it to a specified element array. This method is the designated initializer.
func NewSBObjectWithProperties ¶
func NewSBObjectWithProperties(properties foundation.INSDictionary) SBObject
Returns an instance of an SBObject subclass initialized with the specified properties.
properties: A dictionary with keys specifying the names of properties (that is, attributes or to-one relationships) and the values for those properties.
Return Value ¶
An SBObject object or `nil` if the object could not be initialized.
Discussion ¶
Scripting Bridge does not actually create an object in the target application until you add the object returned from this method to an element array (SBElementArray).
See: https://developer.apple.com/documentation/ScriptingBridge/SBObject/init(properties:)
func SBObjectFromID ¶
SBObjectFromID constructs a SBObject from an objc.ID.
The SBObject class declares methods that can be invoked on any object in a scriptable application. It defines methods for getting elements and properties of an object, as well as setting a given object to a new value.
func (SBObject) Autorelease ¶
Autorelease adds the receiver to the current autorelease pool.
func (SBObject) ElementArrayWithCode ¶
func (s SBObject) ElementArrayWithCode(code coreservices.DescType) ISBElementArray
Returns an array containing every child of the receiver with the given class-type code.
code: A four-character code that identifies a scripting class.
Return Value ¶
An SBElementArray object containing every child of the receiver whose class matches `code`.
Discussion ¶
SBObject subclasses use this method to implement application-specific property accessor methods. You should not need to call this method directly.
See: https://developer.apple.com/documentation/ScriptingBridge/SBObject/elementArray(withCode:)
func (SBObject) EncodeWithCoder ¶
func (s SBObject) EncodeWithCoder(coder foundation.INSCoder)
func (SBObject) Get ¶
func (s SBObject) Get() objectivec.IObject
Forces evaluation of the receiver, causing the real object to be returned immediately.
Return Value ¶
For most properties, the result is a Foundation object such as an [NSString]. For properties with no Foundation equivalent, the result is an [NSAppleEventDescriptor] or another SBObject for most elements.
Discussion ¶
This method forces the current object reference (the receiver) to be evaluated, resulting in the return of the referenced object. By default, Scripting Bridge deals with references to objects until you actually request some concrete data from them or until you call the `get` method.
See: https://developer.apple.com/documentation/ScriptingBridge/SBObject/get()
func (SBObject) InitWithData ¶
func (s SBObject) InitWithData(data objectivec.IObject) SBObject
Returns an instance of an SBObject subclass initialized with the given data.
data: An object containing data for the new SBObject object. The data varies according to the type of scripting object to be created.
Return Value ¶
An SBObject object or `nil` if the object could not be initialized.
Discussion ¶
Scripting Bridge does not actually create an object in the target application until you add the object returned from this method to an element array (SBElementArray).
See: https://developer.apple.com/documentation/ScriptingBridge/SBObject/init(data:)
func (SBObject) InitWithElementCodePropertiesData ¶
func (s SBObject) InitWithElementCodePropertiesData(code coreservices.DescType, properties foundation.INSDictionary, data objectivec.IObject) SBObject
Returns an instance of an SBObject subclass initialized with the specified properties and data and added to the designated element array.
code: A four-character code used to identify an element in the target application’s scripting interface. See Apple Event Manager for details.
properties: A dictionary with NSNumber keys specifying the four-character codes of properties (that is, attributes or to-one relationships) and the values for those properties. Pass `nil` if you are initializing the object by `data` only.
data: An object containing data for the new SBObject object. The data varies according to the type of scripting object to be created. Pass `nil` if you initializing the object by `properties` only.
Return Value ¶
An SBObject object or `nil` if the object could not be initialized.
Discussion ¶
Unlike the other initializers of this class, this method not only initializes the SBObject object but adds it to a specified element array. This method is the designated initializer.
func (SBObject) InitWithProperties ¶
func (s SBObject) InitWithProperties(properties foundation.INSDictionary) SBObject
Returns an instance of an SBObject subclass initialized with the specified properties.
properties: A dictionary with keys specifying the names of properties (that is, attributes or to-one relationships) and the values for those properties.
Return Value ¶
An SBObject object or `nil` if the object could not be initialized.
Discussion ¶
Scripting Bridge does not actually create an object in the target application until you add the object returned from this method to an element array (SBElementArray).
See: https://developer.apple.com/documentation/ScriptingBridge/SBObject/init(properties:)
func (SBObject) LastError ¶
func (s SBObject) LastError() foundation.NSError
The error from the last event this object sent, or nil if it succeeded.
See: https://developer.apple.com/documentation/ScriptingBridge/SBObject/lastError()
func (SBObject) PropertyWithClassCode ¶
func (s SBObject) PropertyWithClassCode(cls objectivec.Class, code coreservices.AEKeyword) ISBObject
Returns an object of the designated scripting class representing the specified property of the receiver
code: A four-character code that uniquely identifies a property of the receiver.
Return Value ¶
An instance of the designated `class` that represents the receiver’s property identified by `code`.
Discussion ¶
SBObject subclasses use this method to implement application-specific property accessor methods. You should not need to call this method directly.
See: https://developer.apple.com/documentation/ScriptingBridge/SBObject/property(with:code:)
func (SBObject) PropertyWithCode ¶
func (s SBObject) PropertyWithCode(code coreservices.AEKeyword) ISBObject
Returns an object representing the specified property of the receiver.
code: A four-character code that uniquely identifies a property of the receiver.
Return Value ¶
An object representing the receiver’s property as identified by `code`.
Discussion ¶
SBObject subclasses use this method to implement application-specific property accessor methods. You should not need to call this method directly.
See: https://developer.apple.com/documentation/ScriptingBridge/SBObject/property(withCode:)
func (SBObject) SetTo ¶
func (s SBObject) SetTo(value objectivec.IObject)
Sets the receiver to a specified value.
value: The data the receiver should be set to. It can be an NSString, NSNumber, NSArray, SBObject, or any other type of object supported by the Scripting Bridge framework.
Discussion ¶
You should not call this method directly.
See: https://developer.apple.com/documentation/ScriptingBridge/SBObject/setTo(_:)
type SBObjectClass ¶
type SBObjectClass struct {
// contains filtered or unexported fields
}
func GetSBObjectClass ¶
func GetSBObjectClass() SBObjectClass
GetSBObjectClass returns the class object for SBObject.
func (SBObjectClass) Alloc ¶
func (sc SBObjectClass) Alloc() SBObject
Alloc allocates memory for a new instance of the class.
func (SBObjectClass) Class ¶
func (sc SBObjectClass) Class() objc.Class
Class returns the underlying Objective-C class pointer.