Crate osascript [] [src]

This library implements limited functionality for the OSA System on macOS. In particular it allows you to execute JavaScript via the OSA system to script applications. It's particularly useful if you need to tell other applications to execute certain functionality.

Currently only JavaScript is supported. Parameters passed to it show up as $params and the return value from the script (as returned with the return keyword) is deserialized later.


extern crate osascript;
#[macro_use] extern crate serde_derive;
struct AlertParams {
    title: String,
    message: String,
    alert_type: String,
    buttons: Vec<String>,
struct AlertResult {
    button: String,
fn main() {
    let script = osascript::JavaScript::new("
        var App = Application('Finder');
        App.includeStandardAdditions = true;
        return App.displayAlert($params.title, {
            message: $params.message,
            'as': $params.alert_type,
            buttons: $params.buttons,
    let rv: AlertResult = script.execute_with_params(AlertParams {
        title: "Shit is on fire!".into(),
        message: "What is happening".into(),
        alert_type: "critical".into(),
        buttons: vec![
            "Show details".into(),
    println!("You clicked '{}'", rv.button);



Holds an apple flavoured JavaScript



The error from the script system