objc2_scripting_bridge/generated/
SBObject.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6#[cfg(feature = "objc2-core-services")]
7use objc2_core_services::*;
8use objc2_foundation::*;
9
10use crate::*;
11
12extern_class!(
13    /// The `SBObject` class declares methods that can be invoked on any object in a
14    /// scriptable application. It defines methods for getting elements and
15    /// properties of an object, as well as setting a given object to a new value.
16    ///
17    /// Each `SBObject` is built around an object specifier, which tells Scripting
18    /// Bridge how to locate the object. Therefore, you can think of an `SBObject`
19    /// as a reference to an object in an target application rather than an object
20    /// itself. To bypass this reference-based approach and force evaluation, use
21    /// the ``SBObject/get`` method.
22    ///
23    /// Typically, rather than create `SBObject` instances explictly, you receive
24    /// `SBObject` objects by calling methods of an ``SBApplication`` subclass. For
25    /// example, if you wanted to get an `SBObject` representing the current iTunes
26    /// track, you would use code like this (where `iTunesTrack` is a subclass of
27    /// `SBObject`):
28    ///
29    /// ```objc
30    /// iTunesApplication *iTunes = [SBApplication applicationWithBundleIdentifier:
31    /// "
32    /// com.apple.iTunes"];
33    /// iTunesTrack *track = [iTunes currentTrack];
34    /// ```
35    ///
36    /// You can discover the names of dynamically generated classes such as
37    /// `iTunesApplication` and `iTunesTrack` by examining the header file created
38    /// by the `sdp` tool. Alternatively, you give these variables the dynamic
39    /// Objective-C type `id`.
40    ///
41    /// See also [Apple's documentation](https://developer.apple.com/documentation/scriptingbridge/sbobject?language=objc)
42    #[unsafe(super(NSObject))]
43    #[derive(Debug, PartialEq, Eq, Hash)]
44    pub struct SBObject;
45);
46
47extern_conformance!(
48    unsafe impl NSCoding for SBObject {}
49);
50
51extern_conformance!(
52    unsafe impl NSObjectProtocol for SBObject {}
53);
54
55impl SBObject {
56    extern_methods!(
57        /// Initializes and returns an instance of an `SBObject` subclass.
58        ///
59        /// Scripting Bridge does not actually create an object in the target
60        /// application until you add the object returned from this method to an element
61        /// array (``SBElementArray``).
62        ///
63        /// - Returns: An `SBObject` object or `nil` if the object could not be
64        /// initialized.
65        #[unsafe(method(init))]
66        #[unsafe(method_family = init)]
67        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
68
69        /// Returns an instance of an `SBObject` subclass initialized with the specified
70        /// properties.
71        ///
72        /// Scripting Bridge does not actually create an object in the target
73        /// application until you add the object returned from this method to an element
74        /// array (``SBElementArray``).
75        ///
76        /// - Parameters:
77        /// - properties: A dictionary with keys specifying the names of properties
78        /// (that is, attributes or to-one relationships) and the values for those
79        /// properties.
80        ///
81        /// - Returns: An `SBObject` object or `nil` if the object could not be
82        /// initialized.
83        #[unsafe(method(initWithProperties:))]
84        #[unsafe(method_family = init)]
85        pub unsafe fn initWithProperties(
86            this: Allocated<Self>,
87            properties: &NSDictionary,
88        ) -> Retained<Self>;
89
90        /// Returns an instance of an `SBObject` subclass initialized with the given
91        /// data.
92        ///
93        /// Scripting Bridge does not actually create an object in the target
94        /// application until you add the object returned from this method to an element
95        /// array (``SBElementArray``).
96        ///
97        /// - Parameters:
98        /// - data: An object containing data for the new `SBObject` object. The data
99        /// varies according to the type of scripting object to be created.
100        ///
101        /// - Returns: An `SBObject` object or `nil` if the object could not be
102        /// initialized.
103        #[unsafe(method(initWithData:))]
104        #[unsafe(method_family = init)]
105        pub unsafe fn initWithData(this: Allocated<Self>, data: &AnyObject) -> Retained<Self>;
106
107        /// Forces evaluation of the receiver, causing the real object to be returned
108        /// immediately.
109        ///
110        /// This method forces the current object reference (the receiver) to be
111        /// evaluated, resulting in the return of the referenced object. By default,
112        /// Scripting Bridge deals with references to objects until you actually request
113        /// some concrete data from them or until you call the `get` method.
114        ///
115        /// - Returns: 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.
116        #[unsafe(method(get))]
117        #[unsafe(method_family = none)]
118        pub unsafe fn get(&self) -> Option<Retained<AnyObject>>;
119
120        /// The error from the last event this object sent, or nil if it succeeded.
121        #[unsafe(method(lastError))]
122        #[unsafe(method_family = none)]
123        pub unsafe fn lastError(&self) -> Option<Retained<NSError>>;
124    );
125}
126
127/// Methods declared on superclass `NSObject`.
128impl SBObject {
129    extern_methods!(
130        #[unsafe(method(new))]
131        #[unsafe(method_family = new)]
132        pub unsafe fn new() -> Retained<Self>;
133    );
134}
135
136/// SBGlueInterface.
137impl SBObject {
138    extern_methods!(
139        #[cfg(feature = "objc2-core-services")]
140        /// Returns an instance of an `SBObject` subclass initialized with the specified
141        /// properties and data and added to the designated element array.
142        ///
143        /// Unlike the other initializers of this class, this method not only
144        /// initializes the `SBObject` object but adds it to a specified element array.
145        /// This method is the designated initializer.
146        ///
147        /// - Parameters:
148        /// - code: A four-character code used to identify an element in the target
149        /// application’s scripting interface. See
150        /// <doc
151        /// ://com.apple.documentation/documentation/applicationservices/apple_event_manager>
152        /// for details.
153        ///
154        /// - properties: A dictionary with
155        /// <doc
156        /// ://com.apple.documentation/documentation/foundation/nsnumber> keys specifying the four-character codes of properties
157        /// (that is, attributes or to-one relationships) and the values for those
158        /// properties. Pass `nil` if you are initializing the object by `data` only.
159        ///
160        /// - data: An object containing data for the new `SBObject` object. The data
161        /// varies according to the type of scripting object to be created. Pass `nil`
162        /// if you initializing the object by `properties` only.
163        ///
164        /// - Returns: An `SBObject` object or `nil` if the object could not be
165        /// initialized.
166        #[unsafe(method(initWithElementCode:properties:data:))]
167        #[unsafe(method_family = init)]
168        pub unsafe fn initWithElementCode_properties_data(
169            this: Allocated<Self>,
170            code: DescType,
171            properties: Option<&NSDictionary<NSString, AnyObject>>,
172            data: Option<&AnyObject>,
173        ) -> Retained<Self>;
174
175        #[cfg(feature = "objc2-core-services")]
176        /// Returns an object representing the specified property of the receiver.
177        ///
178        /// `SBObject` subclasses use this method to implement application-specific
179        /// property accessor methods. You should not need to call this method directly.
180        ///
181        /// - Parameters:
182        /// - code: A four-character code that uniquely identifies a property of the
183        /// receiver.
184        ///
185        /// - Returns: An object representing the receiver’s property as identified by
186        /// `code`.
187        #[unsafe(method(propertyWithCode:))]
188        #[unsafe(method_family = none)]
189        pub unsafe fn propertyWithCode(&self, code: AEKeyword) -> Retained<SBObject>;
190
191        #[cfg(feature = "objc2-core-services")]
192        /// Returns an object of the designated scripting class representing the
193        /// specified property of the receiver
194        ///
195        /// `SBObject` subclasses use this method to implement application-specific
196        /// property accessor methods. You should not need to call this method directly.
197        ///
198        /// > Note: This method doesn't retrieve the value of the property. To get the
199        /// value, call ``get``.
200        ///
201        /// - Parameters:
202        /// - class: The `SBObject` subclass with which to instantiate the object.
203        ///
204        /// - code: A four-character code that uniquely identifies a property of the
205        /// receiver.
206        ///
207        /// - Returns: An instance of the designated `class` that represents the
208        /// receiver’s property identified by `code`.
209        #[unsafe(method(propertyWithClass:code:))]
210        #[unsafe(method_family = none)]
211        pub unsafe fn propertyWithClass_code(
212            &self,
213            cls: &AnyClass,
214            code: AEKeyword,
215        ) -> Retained<SBObject>;
216
217        #[cfg(all(feature = "SBElementArray", feature = "objc2-core-services"))]
218        /// Returns an array containing every child of the receiver with the given
219        /// class-type code.
220        ///
221        /// `SBObject` subclasses use this method to implement application-specific
222        /// property accessor methods. You should not need to call this method directly.
223        ///
224        /// > Note: This method doesn't retrieve the value of the property. To get the
225        /// value, call ``get``.
226        ///
227        /// - Parameters:
228        /// - code: A four-character code that identifies a scripting class.
229        ///
230        /// - Returns: An ``SBElementArray`` object containing every child of the
231        /// receiver whose class matches `code`.
232        #[unsafe(method(elementArrayWithCode:))]
233        #[unsafe(method_family = none)]
234        pub unsafe fn elementArrayWithCode(&self, code: DescType) -> Retained<SBElementArray>;
235
236        /// Sets the receiver to a specified value.
237        ///
238        /// You should not call this method directly.
239        ///
240        /// - Parameters:
241        /// - value: The data the receiver should be set to. It can be an
242        /// <doc
243        /// ://com.apple.documentation/documentation/foundation/nsstring>,
244        /// <doc
245        /// ://com.apple.documentation/documentation/foundation/nsnumber>,
246        /// <doc
247        /// ://com.apple.documentation/documentation/foundation/nsarray>,
248        /// `SBObject`, or any other type of object supported by the Scripting Bridge
249        /// framework.
250        #[unsafe(method(setTo:))]
251        #[unsafe(method_family = none)]
252        pub unsafe fn setTo(&self, value: Option<&AnyObject>);
253    );
254}