objc2_scripting_bridge/generated/
SBApplication.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 `SBApplication` class provides a mechanism enabling an Objective-C
14    /// program to send Apple events to a scriptable application and receive Apple
15    /// events in response. It thereby makes it possible for that program to control
16    /// the application and exchange data with it. Scripting Bridge works by
17    /// bridging data types between Apple event descriptors and Cocoa objects.
18    ///
19    /// Although `SBApplication` includes methods that manually send and process
20    /// Apple events, you should never have to call these methods directly. Instead,
21    /// subclasses of `SBApplication` implement application-specific methods that
22    /// handle the sending of Apple events automatically.
23    ///
24    /// For example, if you wanted to get the current iTunes track, you can simply
25    /// use the `currentTrack` method of the dynamically defined subclass for the
26    /// iTunes application—which handles the details of sending the Apple event for
27    /// you—rather than figuring out the more complicated, low-level alternative:
28    ///
29    /// ```objc
30    /// [iTunes propertyWithCode:'pTrk'];
31    /// ```
32    ///
33    /// If you do need to send Apple events manually, consider using the
34    /// `NSAppleEventDescriptor` class.
35    ///
36    /// ## Subclassing Notes
37    ///
38    /// You rarely instantiate `SBApplication` objects directly. Instead, you get
39    /// the shared instance of a application-specific subclass typically by calling
40    /// one of the `applicationWith...` class methods, using a bundle identifier,
41    /// process identifier, or URL to identify the application.
42    ///
43    /// See also [Apple's documentation](https://developer.apple.com/documentation/scriptingbridge/sbapplication?language=objc)
44    #[unsafe(super(SBObject, NSObject))]
45    #[derive(Debug, PartialEq, Eq, Hash)]
46    #[cfg(feature = "SBObject")]
47    pub struct SBApplication;
48);
49
50#[cfg(feature = "SBObject")]
51extern_conformance!(
52    unsafe impl NSCoding for SBApplication {}
53);
54
55#[cfg(feature = "SBObject")]
56extern_conformance!(
57    unsafe impl NSObjectProtocol for SBApplication {}
58);
59
60#[cfg(feature = "SBObject")]
61impl SBApplication {
62    extern_methods!(
63        /// Returns an instance of an `SBApplication` subclass that represents the
64        /// target application identified by the given bundle identifier.
65        ///
66        /// If you must initialize an `SBApplication` object explictly, you should use
67        /// this initializer if possible; unlike
68        /// ``SBApplication/initWithProcessIdentifier:`` and
69        /// ``SBApplication/initWithURL:``, this method is not dependent on changeable
70        /// factors such as the target application's path or process ID. Even so, you
71        /// should rarely have to initialize an `SBApplication` object yourself;
72        /// instead, you should initialize an application-specific subclass such as
73        /// `iTunesApplication`.
74        ///
75        /// Note that this method does not check whether an application with the given
76        /// bundle identifier actually exists.
77        ///
78        /// - Parameters:
79        /// - ident: A bundle identifier specifying an application that is
80        /// OSA-compliant.
81        ///
82        /// - Returns: An initialized shared instance of an `SBApplication` subclass
83        /// that represents a target application with the bundle identifier of `ident`.
84        /// Returns `nil` if no such application can be found or if the application does
85        /// not have a scripting interface.
86        #[unsafe(method(initWithBundleIdentifier:))]
87        #[unsafe(method_family = init)]
88        pub unsafe fn initWithBundleIdentifier(
89            this: Allocated<Self>,
90            ident: &NSString,
91        ) -> Option<Retained<SBApplication>>;
92
93        /// Returns an instance of an `SBApplication` subclass that represents the
94        /// target application identified by the given URL.
95        ///
96        /// This approach to initializing `SBApplication` objects should be used only if
97        /// you know for certain the URL of the target application. In most cases, it is
98        /// better to use ``SBApplication/applicationWithBundleIdentifier:`` which
99        /// dynamically locates the target application at runtime. Even so, you should
100        /// rarely have to initialize an `SBApplication` yourself.
101        ///
102        /// This method currently supports file URLs (`file:`) and remote application
103        /// URLs (`eppc:`). It checks whether a file exists at the specified path, but
104        /// it does not check whether an application identified via `eppc:` exists.
105        ///
106        /// - Parameters:
107        /// - url: A Universal Resource Locator (URL) specifying an application that is
108        /// OSA-compliant.
109        ///
110        /// - Returns: An initialized `SBApplication` that you can use to communicate
111        /// with the target application specified by the process ID. Returns `nil` if an
112        /// application could not be found or if the application does not have a
113        /// scripting interface.
114        #[unsafe(method(initWithURL:))]
115        #[unsafe(method_family = init)]
116        pub unsafe fn initWithURL(
117            this: Allocated<Self>,
118            url: &NSURL,
119        ) -> Option<Retained<SBApplication>>;
120
121        #[cfg(feature = "libc")]
122        /// Returns an instance of an `SBApplication` subclass that represents the
123        /// target application identified by the given process identifier.
124        ///
125        /// You should avoid using this method unless you know nothing about an external
126        /// application but its PID. In most cases, it is better to use
127        /// ``SBApplication/initWithBundleIdentifier:``, which will dynamically locate
128        /// the external application's path at runtime, or
129        /// ``SBApplication/initWithURL:``, which is not dependent on the external
130        /// application being open at the time the method is called.
131        ///
132        /// - Parameters:
133        /// - pid: A BSD process ID specifying an application that is OSA-compliant.
134        /// Often you can get the process ID of a process using the
135        /// <doc
136        /// ://com.apple.documentation/documentation/foundation/nstask/1412022-processidentifier>
137        /// method of `NSTask`.
138        ///
139        /// - Returns: An initialized `SBApplication` that you can use to communicate
140        /// with the target application specified by the process ID. Returns `nil` if no
141        /// such application can be found or if the application does not have a
142        /// scripting interface.
143        #[unsafe(method(initWithProcessIdentifier:))]
144        #[unsafe(method_family = init)]
145        pub unsafe fn initWithProcessIdentifier(
146            this: Allocated<Self>,
147            pid: libc::pid_t,
148        ) -> Option<Retained<SBApplication>>;
149
150        /// Returns the shared instance representing the target application specified by
151        /// its bundle identifier.
152        ///
153        /// For applications that declare themselves to have a dynamic scripting
154        /// interface, this method will launch the application if it is not already
155        /// running.
156        ///
157        /// - Parameters:
158        /// - ident: A bundle identifier specifying an application that is OSA-compliant.
159        ///
160        /// - Returns: An instance of a `SBApplication` subclass that represents the
161        /// target application whose bundle identifier is `ident`. Returns `nil` if no
162        /// such application can be found or if the application does not have a
163        /// scripting interface.
164        #[unsafe(method(applicationWithBundleIdentifier:))]
165        #[unsafe(method_family = none)]
166        pub unsafe fn applicationWithBundleIdentifier(
167            ident: &NSString,
168        ) -> Option<Retained<SBApplication>>;
169
170        /// Returns the shared instance representing a target application specified by
171        /// the given URL.
172        ///
173        /// For applications that declare themselves to have a dynamic scripting
174        /// interface, this method will launch the application if it is not already
175        /// running. This approach to initializing `SBApplication` objects should be
176        /// used only if you know for certain the URL of the target application. In most
177        /// cases, it is better to use
178        /// ``SBApplication/applicationWithBundleIdentifier:`` which dynamically locates
179        /// the target application at runtime.
180        ///
181        /// This method currently supports file URLs (`file:`) and remote application
182        /// URLs (`eppc:`). It checks whether a file exists at the specified path, but
183        /// it does not check whether an application identified via `eppc:` exists.
184        ///
185        /// - Parameters:
186        /// - url: The Universal Resource Locator (URL) locating an OSA-compliant
187        /// application.
188        ///
189        /// - Returns: An `SBApplication` subclass from which to generate a shared
190        /// instance of the target application whose URL is `url`. Returns `nil` if no
191        /// such application can be found or if the application does not have a
192        /// scripting interface.
193        #[unsafe(method(applicationWithURL:))]
194        #[unsafe(method_family = none)]
195        pub unsafe fn applicationWithURL(url: &NSURL) -> Option<Retained<SBApplication>>;
196
197        #[cfg(feature = "libc")]
198        /// Returns the shared instance representing a target application specified by
199        /// its process identifier.
200        ///
201        /// You should avoid using this method unless you know nothing about a target
202        /// application but its process ID. In most cases, it is better to use
203        /// ``SBApplication/applicationWithBundleIdentifier:``, which will dynamically
204        /// locate the application's path at runtime, or
205        /// ``SBApplication/applicationWithURL:``, which is not dependent on the target
206        /// application being open at the time the method is called.
207        ///
208        /// - Parameters:
209        /// - pid: The BSD process ID of a OSA-compliant application. Often you can get
210        /// the process ID of a process using the
211        /// <doc
212        /// ://com.apple.documentation/documentation/foundation/nstask/1412022-processidentifier>
213        /// method of `NSTask`.
214        ///
215        /// - Returns: An instance of an `SBApplication` subclass that represents the
216        /// target application whose process identifier is `pid`. Returns `nil` if no
217        /// such application can be found or if the application does not have a
218        /// scripting interface.
219        #[unsafe(method(applicationWithProcessIdentifier:))]
220        #[unsafe(method_family = none)]
221        pub unsafe fn applicationWithProcessIdentifier(
222            pid: libc::pid_t,
223        ) -> Option<Retained<SBApplication>>;
224
225        /// Returns a class object that represents a particular class in the target
226        /// application.
227        ///
228        /// You invoke this method on an instance of a scriptable application. Once you
229        /// have the class object, you may allocate an instance of the class and
230        /// appropriately the raw instance. Or you may use it in a call to
231        /// <doc
232        /// ://com.apple.documentation/documentation/objectivec/1418956-nsobject/1418511-iskindofclass>
233        /// to determine the class type of an object.
234        ///
235        /// - Parameters:
236        /// - className: The name of the scripting class, as it appears in the scripting interface. For example, "document".
237        ///
238        /// - Returns: A `Class` object representing the scripting class.
239        #[unsafe(method(classForScriptingClass:))]
240        #[unsafe(method_family = none)]
241        pub unsafe fn classForScriptingClass(
242            &self,
243            class_name: &NSString,
244        ) -> Option<&'static AnyClass>;
245
246        /// A Boolean that indicates whether the target application represented by the
247        /// receiver is running.
248        ///
249        /// <doc
250        /// ://com.apple.documentation/documentation/swift/true> if the application
251        /// is running,
252        /// <doc
253        /// ://com.apple.documentation/documentation/swift/false>
254        /// otherwise.
255        ///
256        /// This may be
257        /// <doc
258        /// ://com.apple.documentation/documentation/swift/true> for instances initialized with a bundle identifier or URL because
259        /// `SBApplication` launches the application only when it's necessary to send
260        /// it an event.
261        #[unsafe(method(isRunning))]
262        #[unsafe(method_family = none)]
263        pub unsafe fn isRunning(&self) -> bool;
264
265        /// Moves the target application to the foreground immediately.
266        ///
267        /// If the target application is not already running, this method launches it.
268        #[unsafe(method(activate))]
269        #[unsafe(method_family = none)]
270        pub unsafe fn activate(&self);
271
272        /// The error-handling delegate of the receiver.
273        ///
274        /// The delegate should implement the
275        /// ``SBApplicationDelegate/eventDidFail:withError:`` method of the
276        /// ``SBApplicationDelegate`` informal protocol.
277        #[unsafe(method(delegate))]
278        #[unsafe(method_family = none)]
279        pub unsafe fn delegate(
280            &self,
281        ) -> Option<Retained<ProtocolObject<dyn SBApplicationDelegate>>>;
282
283        /// Setter for [`delegate`][Self::delegate].
284        #[unsafe(method(setDelegate:))]
285        #[unsafe(method_family = none)]
286        pub unsafe fn setDelegate(
287            &self,
288            delegate: Option<&ProtocolObject<dyn SBApplicationDelegate>>,
289        );
290
291        #[cfg(feature = "objc2-core-services")]
292        /// The launch flags for the application represented by the receiver.
293        ///
294        /// For more information, see
295        /// <doc
296        /// ://com.apple.documentation/documentation/coreservices/launch_services>.
297        #[unsafe(method(launchFlags))]
298        #[unsafe(method_family = none)]
299        pub unsafe fn launchFlags(&self) -> LSLaunchFlags;
300
301        #[cfg(feature = "objc2-core-services")]
302        /// Setter for [`launchFlags`][Self::launchFlags].
303        #[unsafe(method(setLaunchFlags:))]
304        #[unsafe(method_family = none)]
305        pub unsafe fn setLaunchFlags(&self, launch_flags: LSLaunchFlags);
306
307        #[cfg(feature = "objc2-core-services")]
308        /// The mode for sending Apple events to the target application.
309        ///
310        /// For more information, see
311        /// <doc
312        /// ://com.apple.documentation/documentation/applicationservices/apple_event_manager>.
313        ///
314        /// The default send mode is
315        /// <doc
316        /// ://com.apple.documentation/documentation/coreservices/1542914-anonymous/kaewaitreply>.
317        /// If the send mode is something other than `kAEWaitReply`, the receiver might
318        /// not correctly handle reply events from the target application.
319        #[unsafe(method(sendMode))]
320        #[unsafe(method_family = none)]
321        pub unsafe fn sendMode(&self) -> AESendMode;
322
323        #[cfg(feature = "objc2-core-services")]
324        /// Setter for [`sendMode`][Self::sendMode].
325        #[unsafe(method(setSendMode:))]
326        #[unsafe(method_family = none)]
327        pub unsafe fn setSendMode(&self, send_mode: AESendMode);
328
329        /// The period the application will wait to receive reply Apple events.
330        ///
331        /// For more information, see
332        /// <doc
333        /// ://com.apple.documentation/documentation/applicationservices/apple_event_manager>.
334        ///
335        /// The default timeout value is
336        /// <doc
337        /// ://com.apple.documentation/documentation/coreservices/1542814-timeout_constants/kaedefaulttimeout>,
338        /// which is about a minute. If you want the receiver to wait indefinitely for
339        /// reply Apple events, use
340        /// <doc
341        /// ://com.apple.documentation/documentation/coreservices/1542814-timeout_constants/knotimeout>.
342        /// For more information, see
343        /// <doc
344        /// ://com.apple.documentation/documentation/applicationservices/apple_event_manager>.
345        #[unsafe(method(timeout))]
346        #[unsafe(method_family = none)]
347        pub unsafe fn timeout(&self) -> c_long;
348
349        /// Setter for [`timeout`][Self::timeout].
350        #[unsafe(method(setTimeout:))]
351        #[unsafe(method_family = none)]
352        pub unsafe fn setTimeout(&self, timeout: c_long);
353    );
354}
355
356/// Methods declared on superclass `SBObject`.
357#[cfg(feature = "SBObject")]
358impl SBApplication {
359    extern_methods!(
360        /// Initializes and returns an instance of an `SBObject` subclass.
361        ///
362        /// Scripting Bridge does not actually create an object in the target
363        /// application until you add the object returned from this method to an element
364        /// array (``SBElementArray``).
365        ///
366        /// - Returns: An `SBObject` object or `nil` if the object could not be
367        /// initialized.
368        #[unsafe(method(init))]
369        #[unsafe(method_family = init)]
370        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
371
372        /// Returns an instance of an `SBObject` subclass initialized with the specified
373        /// properties.
374        ///
375        /// Scripting Bridge does not actually create an object in the target
376        /// application until you add the object returned from this method to an element
377        /// array (``SBElementArray``).
378        ///
379        /// - Parameters:
380        /// - properties: A dictionary with keys specifying the names of properties
381        /// (that is, attributes or to-one relationships) and the values for those
382        /// properties.
383        ///
384        /// - Returns: An `SBObject` object or `nil` if the object could not be
385        /// initialized.
386        ///
387        /// # Safety
388        ///
389        /// `properties` generic should be of the correct type.
390        #[unsafe(method(initWithProperties:))]
391        #[unsafe(method_family = init)]
392        pub unsafe fn initWithProperties(
393            this: Allocated<Self>,
394            properties: &NSDictionary,
395        ) -> Retained<Self>;
396
397        /// Returns an instance of an `SBObject` subclass initialized with the given
398        /// data.
399        ///
400        /// Scripting Bridge does not actually create an object in the target
401        /// application until you add the object returned from this method to an element
402        /// array (``SBElementArray``).
403        ///
404        /// - Parameters:
405        /// - data: An object containing data for the new `SBObject` object. The data
406        /// varies according to the type of scripting object to be created.
407        ///
408        /// - Returns: An `SBObject` object or `nil` if the object could not be
409        /// initialized.
410        ///
411        /// # Safety
412        ///
413        /// `data` should be of the correct type.
414        #[unsafe(method(initWithData:))]
415        #[unsafe(method_family = init)]
416        pub unsafe fn initWithData(this: Allocated<Self>, data: &AnyObject) -> Retained<Self>;
417    );
418}
419
420/// Methods declared on superclass `NSObject`.
421#[cfg(feature = "SBObject")]
422impl SBApplication {
423    extern_methods!(
424        #[unsafe(method(new))]
425        #[unsafe(method_family = new)]
426        pub unsafe fn new() -> Retained<Self>;
427    );
428}
429
430extern_protocol!(
431    /// This informal protocol defines a delegation method for handling Apple event
432    /// errors that are sent from a target application to an
433    /// <doc
434    /// ://com.apple.documentation/documentation/scriptingbridge/sbapplication>
435    /// object.
436    ///
437    /// You must set a delegate for the ``SBApplication`` object using the
438    /// ``SBApplication/delegate`` method. If you do not set a delegate and have the
439    /// delegate handle the error in some way, ``SBApplication`` raises an
440    /// exception.
441    ///
442    /// See also [Apple's documentation](https://developer.apple.com/documentation/scriptingbridge/sbapplicationdelegate?language=objc)
443    pub unsafe trait SBApplicationDelegate {
444        #[cfg(feature = "objc2-core-services")]
445        /// Sent by an `SBApplication` object when a target application returns an error
446        /// Apple event.
447        ///
448        /// - Parameters:
449        /// - event: A pointer to the Apple event sent to the target application causing
450        /// the error.
451        ///
452        /// - error: An object containing information about the error Apple event.
453        /// Specific information may be included in the `useInfo` dictionary of the
454        /// error object. The following table shows the possible
455        /// keys for this dictionary.
456        ///
457        /// | Key | Description |
458        /// | ----------- | --------------- |
459        /// | ErrorBriefMessage | A short human-readable description of the error, as an
460        /// <doc
461        /// ://com.apple.documentation/documentation/foundation/nsstring> |
462        /// | ErrorExpectedType | The type of data the target application expected, as an
463        /// <doc
464        /// ://com.apple.documentation/documentation/foundation/nsappleeventdescriptor> object. |
465        /// | ErrorOffendingObject | The object that caused the error. |
466        /// | ErrorString | A full human-readable description of the error, as an
467        /// <doc
468        /// ://com.apple.documentation/documentation/foundation/nsstring> object. |
469        /// | ErrorNumber | The Apple event error number, as an
470        /// <doc
471        /// ://com.apple.documentation/documentation/foundation/nsnumber> object. |
472        ///
473        /// - Returns: If you return a result, it will become the result of the
474        /// <doc
475        /// ://com.apple.documentation/documentation/appkit/nsapplication/1428359-sendevent>
476        /// that failed. Can be `nil`.
477        ///
478        /// # Safety
479        ///
480        /// `event` must be a valid pointer.
481        #[unsafe(method(eventDidFail:withError:))]
482        #[unsafe(method_family = none)]
483        unsafe fn eventDidFail_withError(
484            &self,
485            event: NonNull<AppleEvent>,
486            error: &NSError,
487        ) -> Option<Retained<AnyObject>>;
488    }
489);