xai-org/grok-build · error

failed to run osascript: {e}

Error message

failed to run osascript: {e}

What it means

set_image_file (crates/codegen/xai-grok-shared/src/clipboard.rs:1181) copies an image file to the clipboard by running an osascript; this error wraps the io error when osascript itself cannot be launched. Script-level failures instead surface as 'osascript failed: {stderr}'.

Source

Thrown at crates/codegen/xai-grok-shared/src/clipboard.rs:1181

        {
            Some("jpg" | "jpeg") => "JPEG",
            Some("tiff" | "tif") => "TIFF",
            _ => "PNGf",
        };
        let path_str = path.display().to_string().replace('"', "\\\"");
        let script = format!(
            "set the clipboard to (read (POSIX file \"{path_str}\") as \u{00AB}class {class}\u{00BB})"
        );
        let mut cmd = Command::new("osascript");
        cmd.arg("-e")
            .arg(&script)
            .stdin(Stdio::null())
            .stdout(Stdio::null())
            .stderr(Stdio::piped());
        xai_grok_tools::util::detach_std_command(&mut cmd);
        let output = cmd
            .output()
            .map_err(|e| anyhow::anyhow!("failed to run osascript: {e}"))?;

        if !output.status.success() {
            let stderr = String::from_utf8_lossy(&output.stderr);
            anyhow::bail!("osascript failed: {stderr}");
        }
        Ok(())
    }
}

// ---------------------------------------------------------------------------
// Linux / Windows: arboard with CLI-tool fallback on Linux
// ---------------------------------------------------------------------------
#[cfg(not(target_os = "macos"))]
mod platform {
    use super::ImageData;
    use std::process::{Command, Stdio};

    /// No subprocess-free pasteboard probe exists off-macOS.

View on GitHub (pinned to bc7f02eddd)

Solutions

  1. Verify osascript exists: `which osascript`; only run this path on macOS.
  2. Correct the PATH for the invoking process.
  3. Use an alternative image-copy backend (arboard image set) off-macOS.
Defensive patterns

Strategy: fallback

Validate before calling

let osascript_ok = std::process::Command::new("osascript").arg("-e").arg("return 1").output().is_ok();

Try / catch

match set_image_file(path) {
    Err(e) if e.to_string().contains("failed to run osascript") => fallback_image_copy(path),
    other => other,
}

Prevention

When it happens

Trigger: set_image_file called where osascript is absent (Linux/Windows), not executable, or PATH excludes /usr/bin.

Common situations: Linux dev machines running macOS clipboard paths; containers without macOS scripting tools; hardened environments stripping PATH.

Related errors


AI-assisted analysis of xai-org/grok-build@bc7f02eddd (2026-08-31). Data as JSON: /api/errors/b09b141bc46f3cf3. Report an issue: GitHub.