gitbutlerapp/gitbutler · error

osascript directory picker failed

Error message

osascript directory picker failed (exit {:?}): {}

What it means

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).

Solutions

  1. Check the embedded exit code and stderr to identify the osascript failure (permissions vs. missing binary vs. no GUI).
  2. Grant automation/GUI permission to the host process (System Settings > Privacy & Security > Automation), or run in a logged-in GUI session.
  3. Fall back to supplying the path manually (pass the directory as a request parameter) instead of using the native picker.
  4. If the stderr contains "User canceled" but wasn't detected, it is a benign cancellation — handle it as Ok(None) upstream.
Defensive patterns

Strategy: fallback

Validate before calling

// macOS: confirm a GUI session and osascript exist before requesting the native picker
which osascript && [ -n "$DISPLAY" -o "$OSTYPE" = darwin ] && echo ok

Type guard

fn native_picker_supported(os: &str) -> bool {
    matches!(os, "macos" | "linux" | "windows")
}

Try / catch

match pick_directory().await {
    Err(e) if e.to_string().contains("osascript directory picker failed") => {
        let dir = prompt_for_path_manually(); // fallback to text input
    }
    other => other?,
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18). Data as JSON: /api/errors/24183f3e85248471. Report an issue: GitHub.

Appendix: source

Thrown at crates/but-server/src/lib.rs:129

/// Shell out to a platform-native directory picker.
fn native_pick_directory() -> anyhow::Result<Option<String>> {
    #[cfg(target_os = "macos")]
    {
        let output = std::process::Command::new("osascript")
            .arg("-e")
            .arg(
                r#"set theFolder to choose folder with prompt "Select a Git repository"
return POSIX path of theFolder"#,
            )
            .output()?;
        if !output.status.success() {
            let stderr = String::from_utf8_lossy(&output.stderr).trim().to_string();
            // osascript exits with code 1 and "User canceled" on cancel
            if stderr.contains("User canceled") || stderr.contains("(-128)") {
                return Ok(None);
            }
            anyhow::bail!(
                "osascript directory picker failed (exit {:?}): {}",
                output.status.code(),
                if stderr.is_empty() {
                    "unknown error"
                } else {
                    &stderr
                }
            );
        }
        let path = String::from_utf8_lossy(&output.stdout).trim().to_string();
        if path.is_empty() {
            return Ok(None);
        }
        // osascript returns paths with a trailing slash — strip it
        Ok(Some(path.trim_end_matches('/').to_string()))
    }

    #[cfg(target_os = "linux")]

View on GitHub (pinned to 58e5313667)