Skip to content

armgit / peel

Public Imported from GitHub
0

Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.

Drop launchctl's advice to run as root, and name a failed Remove

Țugui Dragoș114e5bc29603
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index 187e5ac3..b45f2305 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -235982,6 +235982,112 @@
}
}
},
+ "“%@” couldn’t be removed." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Položku „%@“ nelze odstranit."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "„%@“ konnte nicht entfernt werden."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "No se ha podido eliminar “%@”."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Impossible de supprimer « %@ »."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Impossibile rimuovere “%@”."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "“%@”を取り除けませんでした。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "‘%@’을(를) 제거할 수 없습니다."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "'%@' kon niet worden verwijderd."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Nie udało się usunąć „%@” z launchd."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Não foi possível remover “%@”."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "„%@” nu a putut fi eliminat."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Не удалось убрать объект «%@»."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "”%@” kunde inte tas bort."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "“%@” kaldırılamadı."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Не вдалося вилучити «%@»."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "未能移除“%@”。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "無法移除「%@」。"
+ }
+ }
+ }
+ },
"“%@” couldn’t be started." : {
"localizations" : {
"cs" : {
diff --git a/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItemActions.swift b/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItemActions.swift
index e35fa4bd..a5c2a650 100644
--- a/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItemActions.swift
+++ b/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItemActions.swift
@@ -147,7 +147,7 @@ public enum BackgroundItemActions {
private static func run(_ arguments: [String]) async throws(Failure) {
let result = await Launchctl.run(arguments)
guard result.status == 0 else {
- throw .launchctl(result.output.trimmingCharacters(in: .whitespacesAndNewlines))
+ throw .launchctl(Launchctl.withoutAdviceToRunAsRoot(result.output))
}
}
diff --git a/Packages/PeelCore/Sources/PeelCore/BackgroundItems/Launchctl.swift b/Packages/PeelCore/Sources/PeelCore/BackgroundItems/Launchctl.swift
index 5cd45095..f88046aa 100644
--- a/Packages/PeelCore/Sources/PeelCore/BackgroundItems/Launchctl.swift
+++ b/Packages/PeelCore/Sources/PeelCore/BackgroundItems/Launchctl.swift
@@ -21,6 +21,15 @@ enum Launchctl {
}
}
+ /// `output` without the line `launchctl` adds after an error, telling whoever typed the command to run it as root
+ /// for richer errors: the person didn't type it, and can't follow it.
+ static func withoutAdviceToRunAsRoot(_ output: String) -> String {
+ output.split(whereSeparator: \.isNewline)
+ .filter { line in !(line.hasPrefix("Try ") && line.hasSuffix(" as root for richer errors.")) }
+ .joined(separator: "\n")
+ .trimmingCharacters(in: .whitespacesAndNewlines)
+ }
+
/// Parses `launchctl list`: "PID\tStatus\tLabel", where PID is "-" for jobs that aren't running. Nil when the
/// output does not start with that header, since another form says nothing.
static func parseList(_ output: String) -> [String: Int32?]? {
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/BackgroundItemActionsTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/BackgroundItemActionsTests.swift
index 81e7209f..65187f0c 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/BackgroundItemActionsTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/BackgroundItemActionsTests.swift
@@ -223,6 +223,15 @@ struct BackgroundItemActionsTests {
#expect(BackgroundItems.Loaded(user: [:], inTheUserDomain: nil).unanswered.lists == [.agent])
}
+ @Test func leavesOutLaunchctlsAdviceToRunItAsRoot() {
+ let bootstrap = "Bootstrap failed: 5: Input/output error\nTry re-running the command as root for richer errors.\n"
+ let kickstart = "Could not kickstart service: 1: Operation not permitted\nTry running `launchctl kickstart -k` as root for richer errors."
+
+ #expect(Launchctl.withoutAdviceToRunAsRoot(bootstrap) == "Bootstrap failed: 5: Input/output error")
+ #expect(Launchctl.withoutAdviceToRunAsRoot(kickstart) == "Could not kickstart service: 1: Operation not permitted")
+ #expect(Launchctl.withoutAdviceToRunAsRoot("Not privileged to start service.") == "Not privileged to start service.")
+ }
+
@Test func aJobWhoseFileIsGoneSaysSo() throws {
let directory = try TemporaryDirectory()
let job = try PropertyListSerialization.data(
diff --git a/Peel/Model/BackgroundItemLibrary.swift b/Peel/Model/BackgroundItemLibrary.swift
index 0a9c9e2e..a457c693 100644
--- a/Peel/Model/BackgroundItemLibrary.swift
+++ b/Peel/Model/BackgroundItemLibrary.swift
@@ -94,6 +94,8 @@ final class BackgroundItemLibrary {
enum Action {
case start
case stop
+ /// Stop under the name macOS 27's page gives it for a job its gone app left loaded.
+ case remove
case enable
case disable
case moveToTrash
@@ -141,7 +143,7 @@ final class BackgroundItemLibrary {
do {
switch action {
case .start: try await BackgroundItemActions.start(item)
- case .stop: try await BackgroundItemActions.stop(item)
+ case .stop, .remove: try await BackgroundItemActions.stop(item)
case .enable:
try await BackgroundItemActions.setEnabled(true, for: item)
noteEnabled(item)
diff --git a/Peel/Views/BackgroundItems/BackgroundItemDetailView.swift b/Peel/Views/BackgroundItems/BackgroundItemDetailView.swift
index 29d1dbf0..8c17c69b 100644
--- a/Peel/Views/BackgroundItems/BackgroundItemDetailView.swift
+++ b/Peel/Views/BackgroundItems/BackgroundItemDetailView.swift
@@ -418,7 +418,7 @@ struct BackgroundItemDetailView: View {
.help(item.isFileGone ? Text(verbatim: "") : Text("Takes it out of launchd. Its file stays where it is, and it runs again only if something loads it again."))
} else if #available(macOS 27, *), item.isLeftByAGoneApp {
Button("Remove", systemImage: "xmark.circle") {
- Task { await backgroundItems.perform(.stop, on: item) }
+ Task { await backgroundItems.perform(.remove, on: item) }
}
.help(removeHelp)
} else {
diff --git a/Peel/Views/BackgroundItems/BackgroundItemList.swift b/Peel/Views/BackgroundItems/BackgroundItemList.swift
index 708ae8d2..92b7e60e 100644
--- a/Peel/Views/BackgroundItems/BackgroundItemList.swift
+++ b/Peel/Views/BackgroundItems/BackgroundItemList.swift
@@ -140,6 +140,7 @@ struct BackgroundItemList: View {
return switch failure.action {
case .start: Text("“\(label)” couldn’t be started.")
case .stop: Text("“\(label)” couldn’t be stopped.")
+ case .remove: Text("“\(label)” couldn’t be removed.")
case .enable: Text("“\(label)” couldn’t be enabled.")
case .disable: Text("“\(label)” couldn’t be disabled.")
case .moveToTrash where failure.fileMoved: Text("“\(label)” is in the Trash but couldn’t be stopped.")