{"record":{"id":"5a9ff51786432764","repo":"tonhowtf/omniget","slug":"osascript-failed","errorCode":null,"errorMessage":"osascript failed: {}","messagePattern":"osascript failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/clipboard.rs","lineNumber":49,"sourceCode":"}\n\n#[cfg(target_os = \"macos\")]\nasync fn copy_file_macos(path: &str) -> anyhow::Result<()> {\n    let path = path.to_string();\n    let output = tokio::task::spawn_blocking(move || {\n        crate::core::process::std_command(\"osascript\")\n            .args([\n                \"-e\",\n                &format!(\"set the clipboard to POSIX file \\\"{}\\\"\", path),\n            ])\n            .output()\n    })\n    .await\n    .map_err(|e| anyhow::anyhow!(\"spawn_blocking failed: {}\", e))??;\n\n    if !output.status.success() {\n        let stderr = String::from_utf8_lossy(&output.stderr);\n        return Err(anyhow::anyhow!(\"osascript failed: {}\", stderr));\n    }\n\n    tracing::info!(\"[clipboard] copied file to clipboard (macOS)\");\n    Ok(())\n}\n\n#[cfg(target_os = \"linux\")]\nasync fn copy_file_linux(path: &str) -> anyhow::Result<()> {\n    let uri = format!(\"file://{}\", path);\n\n    let uri_clone = uri.clone();\n    let xclip_result = tokio::task::spawn_blocking(move || {\n        let mut child = match crate::core::process::std_command(\"xclip\")\n            .args([\"-selection\", \"clipboard\", \"-target\", \"text/uri-list\"])\n            .stdin(std::process::Stdio::piped())\n            .spawn()\n        {\n            Ok(c) => c,","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/clipboard.rs#L31-L67","documentation":"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: {}'.","triggerScenarios":"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.","commonSituations":"Files with quotes in their names breaking the AppleScript string interpolation; TCC privacy permissions denying osascript automation; running headless where no clipboard service exists.","solutions":["Check the stderr in the error message for the AppleScript error and fix the path (escape/normalize it).","Verify the file exists at the exact path before copying.","Grant the terminal/app Automation permissions in System Settings > Privacy & Security, or test osascript manually.","Avoid double quotes in the filename, or copy from a path without special characters."],"exampleFix":"// before\nlet path = \"/tmp/weird \\\"quoted\\\" file.mp4\"; // breaks AppleScript string\n// after\nlet path = \"/tmp/weird_quoted_file.mp4\"; // sanitize or rename before copying","handlingStrategy":"try-catch","validationCode":"if (!fs.existsSync(filePath)) throw new Error(`File does not exist: ${filePath}`);\nif (/[\"\\\\]/.test(path.basename(filePath))) console.warn('Path contains characters that break AppleScript');","typeGuard":null,"tryCatchPattern":"match copy_file_to_clipboard(path).await {\n    Err(e) if e.to_string().starts_with(\"osascript failed\") => {\n        eprintln!(\"Clipboard copy failed on macOS: {e}; check file path and Automation permissions\");\n    }\n    other => other?,\n}","preventionTips":["Sanitize or escape double quotes in file paths before clipboard copy","Verify the file exists before attempting the copy","Grant Automation permissions to the host app/terminal on macOS"],"tags":["macos","clipboard","process"],"backgroundTag":"git-command-failed","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}