tonhowtf/omniget · error

osascript failed

Error message

osascript failed: {}

What it means

On macOS, copying a file to the clipboard shells out to osascript with an AppleScript that sets the clipboard to a POSIX file. If osascript exits non-zero, its stderr is surfaced as 'osascript failed: {}'.

Solutions

  1. Check the stderr in the error message for the AppleScript error and fix the path (escape/normalize it).
  2. Verify the file exists at the exact path before copying.
  3. Grant the terminal/app Automation permissions in System Settings > Privacy & Security, or test osascript manually.
  4. Avoid double quotes in the filename, or copy from a path without special characters.

Example fix

// before
let path = "/tmp/weird \"quoted\" file.mp4"; // breaks AppleScript string
// after
let path = "/tmp/weird_quoted_file.mp4"; // sanitize or rename before copying
Defensive patterns

Strategy: try-catch

Validate before calling

if (!fs.existsSync(filePath)) throw new Error(`File does not exist: ${filePath}`);
if (/["\\]/.test(path.basename(filePath))) console.warn('Path contains characters that break AppleScript');

Try / catch

match copy_file_to_clipboard(path).await {
    Err(e) if e.to_string().starts_with("osascript failed") => {
        eprintln!("Clipboard copy failed on macOS: {e}; check file path and Automation permissions");
    }
    other => other?,
}

Prevention

When it happens

Trigger: copy_file_to_clipboard on macOS when osascript rejects the script — e.g. the file path contains unescaped double quotes, the file doesn't exist, or Automation permissions block osascript.

Common situations: Files with quotes in their names breaking the AppleScript string interpolation; TCC privacy permissions denying osascript automation; running headless where no clipboard service exists.

Understand the failure class

Background: "git command failed": what it means when a tool shells out to git and git exits non-zero — this error's family across 21 libraries.

Related errors


AI-assisted analysis of tonhowtf/omniget@8600b91f42 (2026-09-12). Data as JSON: /api/errors/5a9ff51786432764. Report an issue: GitHub.

Appendix: source

Thrown at src-tauri/omniget-core/src/core/clipboard.rs:49

}

#[cfg(target_os = "macos")]
async fn copy_file_macos(path: &str) -> anyhow::Result<()> {
    let path = path.to_string();
    let output = tokio::task::spawn_blocking(move || {
        crate::core::process::std_command("osascript")
            .args([
                "-e",
                &format!("set the clipboard to POSIX file \"{}\"", path),
            ])
            .output()
    })
    .await
    .map_err(|e| anyhow::anyhow!("spawn_blocking failed: {}", e))??;

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

    tracing::info!("[clipboard] copied file to clipboard (macOS)");
    Ok(())
}

#[cfg(target_os = "linux")]
async fn copy_file_linux(path: &str) -> anyhow::Result<()> {
    let uri = format!("file://{}", path);

    let uri_clone = uri.clone();
    let xclip_result = tokio::task::spawn_blocking(move || {
        let mut child = match crate::core::process::std_command("xclip")
            .args(["-selection", "clipboard", "-target", "text/uri-list"])
            .stdin(std::process::Stdio::piped())
            .spawn()
        {
            Ok(c) => c,

View on GitHub (pinned to 8600b91f42)