{"record":{"id":"24183f3e85248471","repo":"gitbutlerapp/gitbutler","slug":"osascript-directory-picker-failed-exit","errorCode":null,"errorMessage":"osascript directory picker failed (exit {:?}): {}","messagePattern":"osascript directory picker failed \\(exit (.+?)\\): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-server/src/lib.rs","lineNumber":129,"sourceCode":"\n/// Shell out to a platform-native directory picker.\nfn native_pick_directory() -> anyhow::Result<Option<String>> {\n    #[cfg(target_os = \"macos\")]\n    {\n        let output = std::process::Command::new(\"osascript\")\n            .arg(\"-e\")\n            .arg(\n                r#\"set theFolder to choose folder with prompt \"Select a Git repository\"\nreturn POSIX path of theFolder\"#,\n            )\n            .output()?;\n        if !output.status.success() {\n            let stderr = String::from_utf8_lossy(&output.stderr).trim().to_string();\n            // osascript exits with code 1 and \"User canceled\" on cancel\n            if stderr.contains(\"User canceled\") || stderr.contains(\"(-128)\") {\n                return Ok(None);\n            }\n            anyhow::bail!(\n                \"osascript directory picker failed (exit {:?}): {}\",\n                output.status.code(),\n                if stderr.is_empty() {\n                    \"unknown error\"\n                } else {\n                    &stderr\n                }\n            );\n        }\n        let path = String::from_utf8_lossy(&output.stdout).trim().to_string();\n        if path.is_empty() {\n            return Ok(None);\n        }\n        // osascript returns paths with a trailing slash — strip it\n        Ok(Some(path.trim_end_matches('/').to_string()))\n    }\n\n    #[cfg(target_os = \"linux\")]","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-server/src/lib.rs#L111-L147","documentation":"On macOS, `native_pick_directory` in but-server opens a folder chooser by shelling out to `osascript` (AppleScript). If the osascript process exits non-zero and the stderr is not the normal \"User canceled\"/error -128 case, the server reports the failure as this error, including the exit code and stderr text (or \"unknown error\" when stderr is empty).","triggerScenarios":"Invoking the native directory-pick endpoint on macOS when the `osascript` process fails: osascript binary missing/unusable, AppleScript syntax/automation permission failure, headless environment, or any non-cancellation non-zero exit.","commonSituations":"Running but-server over SSH or in a CI/container with no GUI so the picker cannot launch; macOS privacy/automation permissions blocking the dialog; a user cancellation variant whose stderr text doesn't match the expected patterns.","solutions":["Check the embedded exit code and stderr to identify the osascript failure (permissions vs. missing binary vs. no GUI).","Grant automation/GUI permission to the host process (System Settings > Privacy & Security > Automation), or run in a logged-in GUI session.","Fall back to supplying the path manually (pass the directory as a request parameter) instead of using the native picker.","If the stderr contains \"User canceled\" but wasn't detected, it is a benign cancellation — handle it as Ok(None) upstream."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// macOS: confirm a GUI session and osascript exist before requesting the native picker\nwhich osascript && [ -n \"$DISPLAY\" -o \"$OSTYPE\" = darwin ] && echo ok","typeGuard":"fn native_picker_supported(os: &str) -> bool {\n    matches!(os, \"macos\" | \"linux\" | \"windows\")\n}","tryCatchPattern":"match pick_directory().await {\n    Err(e) if e.to_string().contains(\"osascript directory picker failed\") => {\n        let dir = prompt_for_path_manually(); // fallback to text input\n    }\n    other => other?,\n}","preventionTips":["Run the server in a logged-in GUI session on macOS; avoid SSH/headless contexts for picker calls.","Grant the host process automation permissions before invoking osascript dialogs.","Provide a manual path-entry fallback in clients so a picker failure never blocks the workflow.","Treat 'User canceled' / (-128) stderr as a normal cancellation, not an error."],"tags":["macos","osascript","native-dialog","process"],"backgroundTag":"command-not-found","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}