From 6ef9544c02b63b400f4df2d2336bc6fcdf2be1d1 Mon Sep 17 00:00:00 2001 From: Philipp Klocke Date: Sat, 30 May 2026 20:52:27 +0200 Subject: [PATCH] Fix sketchybar invocation to work with non-Homebrew installs URL(fileURLWithPath: sketchybarPath) only works when the binary is at a hardcoded well-known Homebrew path. Users on Nix, MacPorts, or any other package manager have sketchybar on their PATH but not at /opt/homebrew or /usr/local, so the process would launch the wrong path or fail entirely. Drop the path-guessing logic and always invoke via /usr/bin/env so the system PATH is used to resolve the binary regardless of how it was installed. Co-Authored-By: Claude Sonnet 4.6 --- .../PrerequisiteChecker.swift | 16 +++------------ .../SketchyBarController.swift | 20 +++++-------------- 2 files changed, 8 insertions(+), 28 deletions(-) diff --git a/Sources/SketchyBarToggleCore/PrerequisiteChecker.swift b/Sources/SketchyBarToggleCore/PrerequisiteChecker.swift index 9708c07..26cf8d3 100644 --- a/Sources/SketchyBarToggleCore/PrerequisiteChecker.swift +++ b/Sources/SketchyBarToggleCore/PrerequisiteChecker.swift @@ -25,17 +25,7 @@ public struct PrerequisiteReport { } public final class PrerequisiteChecker { - private let sketchybarPath: String - - public init() { - if FileManager.default.fileExists(atPath: "/opt/homebrew/bin/sketchybar") { - sketchybarPath = "/opt/homebrew/bin/sketchybar" - } else if FileManager.default.fileExists(atPath: "/usr/local/bin/sketchybar") { - sketchybarPath = "/usr/local/bin/sketchybar" - } else { - sketchybarPath = "sketchybar" - } - } + public init() {} public func check() -> PrerequisiteReport { var issues: [String] = [] @@ -95,8 +85,8 @@ public final class PrerequisiteChecker { private func querySketchyBar() -> (running: Bool, topmost: String?) { let process = Process() - process.executableURL = URL(fileURLWithPath: sketchybarPath) - process.arguments = ["--query", "bar"] + process.executableURL = URL(fileURLWithPath: "/usr/bin/env") + process.arguments = ["sketchybar", "--query", "bar"] let pipe = Pipe() process.standardOutput = pipe diff --git a/Sources/SketchyBarToggleCore/SketchyBarController.swift b/Sources/SketchyBarToggleCore/SketchyBarController.swift index bfb2487..5b0eab5 100644 --- a/Sources/SketchyBarToggleCore/SketchyBarController.swift +++ b/Sources/SketchyBarToggleCore/SketchyBarController.swift @@ -2,17 +2,7 @@ import Foundation /// Controls SketchyBar visibility by shelling out to the `sketchybar` CLI. public final class SketchyBarController: BarController { - private let sketchybarPath: String - - public init() { - if FileManager.default.fileExists(atPath: "/opt/homebrew/bin/sketchybar") { - sketchybarPath = "/opt/homebrew/bin/sketchybar" - } else if FileManager.default.fileExists(atPath: "/usr/local/bin/sketchybar") { - sketchybarPath = "/usr/local/bin/sketchybar" - } else { - sketchybarPath = "sketchybar" - } - } + public init() {} public func hide() { // Instant hide — macOS menu bar is already sliding in @@ -27,8 +17,8 @@ public final class SketchyBarController: BarController { private func run(arguments: [String]) { let process = Process() - process.executableURL = URL(fileURLWithPath: sketchybarPath) - process.arguments = arguments + process.executableURL = URL(fileURLWithPath: "/usr/bin/env") + process.arguments = ["sketchybar"] + arguments process.standardOutput = FileHandle.nullDevice process.standardError = FileHandle.nullDevice @@ -42,8 +32,8 @@ public final class SketchyBarController: BarController { private func runAsync(arguments: [String]) { let process = Process() - process.executableURL = URL(fileURLWithPath: sketchybarPath) - process.arguments = arguments + process.executableURL = URL(fileURLWithPath: "/usr/bin/env") + process.arguments = ["sketchybar"] + arguments process.standardOutput = FileHandle.nullDevice process.standardError = FileHandle.nullDevice