Firstly run the specified app, then alert a dialog. Return the clicked button value. # Arguments `app` - The app to execute the script. `alert_type` - Alert type. . informational, warning, critical `title` - The alert title. `message` - The alert message. `buttons` - The buttons to show.
(
app: String,
alert_type: String,
title: String,
message: String,
buttons: Vec<String>,
)
| 26 | /// * `message` - The alert message. |
| 27 | /// * `buttons` - The buttons to show. |
| 28 | pub fn alert( |
| 29 | app: String, |
| 30 | alert_type: String, |
| 31 | title: String, |
| 32 | message: String, |
| 33 | buttons: Vec<String>, |
| 34 | ) -> ResultType<String> { |
| 35 | let script = osascript::JavaScript::new(&format!( |
| 36 | " |
| 37 | var App = Application('{}'); |
| 38 | App.includeStandardAdditions = true; |
| 39 | return App.displayAlert($params.title, {{ |
| 40 | message: $params.message, |
| 41 | 'as': $params.alert_type, |
| 42 | buttons: $params.buttons, |
| 43 | }}); |
| 44 | ", |
| 45 | app |
| 46 | )); |
| 47 | |
| 48 | let result: AlertResult = script.execute_with_params(AlertParams { |
| 49 | title, |
| 50 | message, |
| 51 | alert_type, |
| 52 | buttons, |
| 53 | })?; |
| 54 | Ok(result.button) |
| 55 | } |