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 ///
84 /// # Safety
85 ///
86 /// `properties` generic should be of the correct type.
87 #[unsafe(method(initWithProperties:))]
88 #[unsafe(method_family = init)]
89 pub unsafe fn initWithProperties(
90 this: Allocated<Self>,
91 properties: &NSDictionary,
92 ) -> Retained<Self>;
93
94 /// Returns an instance of an `SBObject` subclass initialized with the given
95 /// data.
96 ///
97 /// Scripting Bridge does not actually create an object in the target
98 /// application until you add the object returned from this method to an element
99 /// array (``SBElementArray``).
100 ///
101 /// - Parameters:
102 /// - data: An object containing data for the new `SBObject` object. The data
103 /// varies according to the type of scripting object to be created.
104 ///
105 /// - Returns: An `SBObject` object or `nil` if the object could not be
106 /// initialized.
107 ///
108 /// # Safety
109 ///
110 /// `data` should be of the correct type.
111 #[unsafe(method(initWithData:))]
112 #[unsafe(method_family = init)]
113 pub unsafe fn initWithData(this: Allocated<Self>, data: &AnyObject) -> Retained<Self>;
114
115 /// Forces evaluation of the receiver, causing the real object to be returned
116 /// immediately.
117 ///
118 /// This method forces the current object reference (the receiver) to be
119 /// evaluated, resulting in the return of the referenced object. By default,
120 /// Scripting Bridge deals with references to objects until you actually request
121 /// some concrete data from them or until you call the `get` method.
122 ///
123 /// - 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.
124 #[unsafe(method(get))]
125 #[unsafe(method_family = none)]
126 pub unsafe fn get(&self) -> Option<Retained<AnyObject>>;
127
128 /// The error from the last event this object sent, or nil if it succeeded.
129 #[unsafe(method(lastError))]
130 #[unsafe(method_family = none)]
131 pub unsafe fn lastError(&self) -> Option<Retained<NSError>>;
132 );
133}
134
135/// Methods declared on superclass `NSObject`.
136impl SBObject {
137 extern_methods!(
138 #[unsafe(method(new))]
139 #[unsafe(method_family = new)]
140 pub unsafe fn new() -> Retained<Self>;
141 );
142}
143
144/// SBGlueInterface.
145impl SBObject {
146 extern_methods!(
147 #[cfg(feature = "objc2-core-services")]
148 /// Returns an instance of an `SBObject` subclass initialized with the specified
149 /// properties and data and added to the designated element array.
150 ///
151 /// Unlike the other initializers of this class, this method not only
152 /// initializes the `SBObject` object but adds it to a specified element array.
153 /// This method is the designated initializer.
154 ///
155 /// - Parameters:
156 /// - code: A four-character code used to identify an element in the target
157 /// application’s scripting interface. See
158 /// <doc
159 /// ://com.apple.documentation/documentation/applicationservices/apple_event_manager>
160 /// for details.
161 ///
162 /// - properties: A dictionary with
163 /// <doc
164 /// ://com.apple.documentation/documentation/foundation/nsnumber> keys specifying the four-character codes of properties
165 /// (that is, attributes or to-one relationships) and the values for those
166 /// properties. Pass `nil` if you are initializing the object by `data` only.
167 ///
168 /// - data: An object containing data for the new `SBObject` object. The data
169 /// varies according to the type of scripting object to be created. Pass `nil`
170 /// if you initializing the object by `properties` only.
171 ///
172 /// - Returns: An `SBObject` object or `nil` if the object could not be
173 /// initialized.
174 ///
175 /// # Safety
176 ///
177 /// - `properties` generic should be of the correct type.
178 /// - `data` should be of the correct type.
179 #[unsafe(method(initWithElementCode:properties:data:))]
180 #[unsafe(method_family = init)]
181 pub unsafe fn initWithElementCode_properties_data(
182 this: Allocated<Self>,
183 code: DescType,
184 properties: Option<&NSDictionary<NSString, AnyObject>>,
185 data: Option<&AnyObject>,
186 ) -> Retained<Self>;
187
188 #[cfg(feature = "objc2-core-services")]
189 /// Returns an object representing the specified property of the receiver.
190 ///
191 /// `SBObject` subclasses use this method to implement application-specific
192 /// property accessor methods. You should not need to call this method directly.
193 ///
194 /// - Parameters:
195 /// - code: A four-character code that uniquely identifies a property of the
196 /// receiver.
197 ///
198 /// - Returns: An object representing the receiver’s property as identified by
199 /// `code`.
200 #[unsafe(method(propertyWithCode:))]
201 #[unsafe(method_family = none)]
202 pub unsafe fn propertyWithCode(&self, code: AEKeyword) -> Retained<SBObject>;
203
204 #[cfg(feature = "objc2-core-services")]
205 /// Returns an object of the designated scripting class representing the
206 /// specified property of the receiver
207 ///
208 /// `SBObject` subclasses use this method to implement application-specific
209 /// property accessor methods. You should not need to call this method directly.
210 ///
211 /// > Note: This method doesn't retrieve the value of the property. To get the
212 /// value, call ``get``.
213 ///
214 /// - Parameters:
215 /// - class: The `SBObject` subclass with which to instantiate the object.
216 ///
217 /// - code: A four-character code that uniquely identifies a property of the
218 /// receiver.
219 ///
220 /// - Returns: An instance of the designated `class` that represents the
221 /// receiver’s property identified by `code`.
222 ///
223 /// # Safety
224 ///
225 /// `cls` probably has further requirements.
226 #[unsafe(method(propertyWithClass:code:))]
227 #[unsafe(method_family = none)]
228 pub unsafe fn propertyWithClass_code(
229 &self,
230 cls: &AnyClass,
231 code: AEKeyword,
232 ) -> Retained<SBObject>;
233
234 #[cfg(all(feature = "SBElementArray", feature = "objc2-core-services"))]
235 /// Returns an array containing every child of the receiver with the given
236 /// class-type code.
237 ///
238 /// `SBObject` subclasses use this method to implement application-specific
239 /// property accessor methods. You should not need to call this method directly.
240 ///
241 /// > Note: This method doesn't retrieve the value of the property. To get the
242 /// value, call ``get``.
243 ///
244 /// - Parameters:
245 /// - code: A four-character code that identifies a scripting class.
246 ///
247 /// - Returns: An ``SBElementArray`` object containing every child of the
248 /// receiver whose class matches `code`.
249 #[unsafe(method(elementArrayWithCode:))]
250 #[unsafe(method_family = none)]
251 pub unsafe fn elementArrayWithCode(&self, code: DescType) -> Retained<SBElementArray>;
252
253 /// Sets the receiver to a specified value.
254 ///
255 /// You should not call this method directly.
256 ///
257 /// - Parameters:
258 /// - value: The data the receiver should be set to. It can be an
259 /// <doc
260 /// ://com.apple.documentation/documentation/foundation/nsstring>,
261 /// <doc
262 /// ://com.apple.documentation/documentation/foundation/nsnumber>,
263 /// <doc
264 /// ://com.apple.documentation/documentation/foundation/nsarray>,
265 /// `SBObject`, or any other type of object supported by the Scripting Bridge
266 /// framework.
267 ///
268 /// # Safety
269 ///
270 /// `value` should be of the correct type.
271 #[unsafe(method(setTo:))]
272 #[unsafe(method_family = none)]
273 pub unsafe fn setTo(&self, value: Option<&AnyObject>);
274 );
275}