From dc5afa13dbea4da042c35e12291c5b5a2846c3ff Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Sat, 4 Jun 2022 17:43:48 +0300 Subject: [PATCH] notifications: use osascript/applescript for notifications on macos --- src/components/notifications.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/components/notifications.rs b/src/components/notifications.rs index 0aa47cd9..5e5dcf14 100644 --- a/src/components/notifications.rs +++ b/src/components/notifications.rs @@ -210,6 +210,32 @@ impl Component for NotificationCommand { debug!("Could not run notification script: {:?}", err); } } + } else { + #[cfg(target_os = "macos")] + { + let applescript = format!("display notification \"{message}\" with title \"{title}\" subtitle \"{subtitle}\"", message = body.replace('"', "'"), title = title.as_ref().map(String::as_str).unwrap_or("meli"), subtitle = kind.map(|k| k.to_string()).unwrap_or_default()); + match Command::new("osascript") + .arg("-e") + .arg(applescript) + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .spawn() + { + Ok(child) => { + context.children.push(child); + } + Err(err) => { + log( + format!( + "Could not run notification script: {}.", + err.to_string() + ), + ERROR, + ); + debug!("Could not run notification script: {:?}", err); + } + } + } } }