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.

Background Items lists jobs loaded from elsewhere or with no known app

Țugui Dragoș29ce4a64df1b
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index 2ecc9702..79d9e58e 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -52293,6 +52293,112 @@
}
}
},
+ "Loaded from a file elsewhere" : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Načteno ze souboru na jiném místě"
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Aus einer Datei an anderer Stelle geladen"
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Cargado desde un archivo en otro lugar"
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Chargé depuis un fichier situé ailleurs"
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Caricato da un file in un’altra cartella"
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "ほかの場所にあるファイルから読み込まれています"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "다른 위치의 파일에서 로드됨"
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Geladen uit een bestand elders"
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Wczytano z pliku w innym miejscu"
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Carregado de um arquivo em outro local"
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Încărcat dintr‑un fișier din altă parte"
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Загружено из файла в другом месте"
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Inläst från en fil någon annanstans"
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Başka bir yerdeki dosyadan yüklendi"
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Завантажено з файлу в іншому місці"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "从其他位置的文件载入"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "從其他位置的檔案載入"
+ }
+ }
+ }
+ },
"Location" : {
"localizations" : {
"cs" : {
@@ -103719,6 +103825,218 @@
}
}
},
+ "Something loaded this from a file outside the folders macOS reads at login, so macOS forgets it when you log out. The file is shown above." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Něco tuto úlohu načetlo ze souboru mimo složky, které macOS čte při přihlášení, takže ji macOS po odhlášení zapomene. Soubor je zobrazený výše."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Etwas hat dieses Objekt aus einer Datei außerhalb der Ordner geladen, die macOS bei der Anmeldung liest, daher vergisst macOS es, wenn du dich abmeldest. Die Datei wird oben angezeigt."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Algo lo ha cargado desde un archivo fuera de las carpetas que macOS lee al iniciar sesión, así que macOS lo olvida cuando cierras sesión. El archivo aparece arriba."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Cet élément a été chargé depuis un fichier situé en dehors des dossiers que macOS lit à l’ouverture de session, si bien que macOS l’oublie lorsque vous fermez la session. Le fichier est indiqué ci-dessus."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Qualcosa l’ha caricato da un file fuori dalle cartelle che macOS legge al login, quindi macOS lo dimentica quando esegui il logout. Il file è mostrato qui sopra."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOSがログイン時に読み込むフォルダの外にあるファイルから、何かがこれを読み込みました。そのため、ログアウトするとmacOSはこれを忘れます。そのファイルは上に表示されています。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS가 로그인 시 읽는 폴더 밖의 파일에서 무언가가 이 항목을 로드했으므로, 로그아웃하면 macOS가 이 항목을 잊습니다. 파일은 위에 표시되어 있습니다."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Iets heeft dit geladen uit een bestand buiten de mappen die macOS bij het inloggen leest, dus macOS vergeet het als je uitlogt. Het bestand staat hierboven."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Coś wczytało tę rzecz z pliku spoza folderów, które macOS odczytuje podczas logowania, więc macOS zapomni o niej, gdy się wylogujesz. Ten plik jest pokazany powyżej."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Algo carregou este item de um arquivo fora das pastas que o macOS lê ao iniciar a sessão, então o macOS o esquece quando você finaliza a sessão. O arquivo aparece acima."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Ceva l‑a încărcat dintr‑un fișier aflat în afara dosarelor pe care macOS le citește la login, așa că macOS îl uită când faceți logout. Fișierul este afișat mai sus."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Что-то загрузило этот объект из файла вне папок, которые macOS читает при входе в систему, поэтому macOS забудет о нем, когда Вы выйдете из системы. Файл показан выше."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Något läste in det här från en fil utanför de mappar som macOS läser vid inloggning, så macOS glömmer det när du loggar ut. Filen visas ovan."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Bu, macOS’in oturum açıldığında okuduğu klasörlerin dışındaki bir dosyadan yüklendi, bu yüzden macOS oturumu kapattığınızda onu unutur. Dosya yukarıda gösteriliyor."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Щось завантажило цей елемент з файлу поза папками, які macOS читає під час входу в систему, тож macOS забуває про нього, коли ви виходите із системи. Файл показано вище."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "某个程序从macOS在登录时读取的文件夹之外的文件载入了此项,因此你退出登录时,macOS会忘记它。该文件显示在上方。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "有東西從macOS在登入時讀取的檔案夾以外的檔案載入了此項目,因此你登出時macOS就會忘記它。該檔案顯示於上方。"
+ }
+ }
+ }
+ },
+ "Something loaded this from a file outside the folders macOS reads at startup, so macOS forgets it when the Mac restarts. The file is shown above." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Něco tuto úlohu načetlo ze souboru mimo složky, které macOS čte při startu, takže ji macOS po restartu Macu zapomene. Soubor je zobrazený výše."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Etwas hat dieses Objekt aus einer Datei außerhalb der Ordner geladen, die macOS beim Systemstart liest, daher vergisst macOS es, wenn der Mac neu startet. Die Datei wird oben angezeigt."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Algo lo ha cargado desde un archivo fuera de las carpetas que macOS lee al arrancar, así que macOS lo olvida cuando el Mac se reinicia. El archivo aparece arriba."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Cet élément a été chargé depuis un fichier situé en dehors des dossiers que macOS lit au démarrage, si bien que macOS l’oublie lorsque le Mac redémarre. Le fichier est indiqué ci-dessus."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Qualcosa l’ha caricato da un file fuori dalle cartelle che macOS legge all’avvio, quindi macOS lo dimentica quando il Mac si riavvia. Il file è mostrato qui sopra."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOSが起動時に読み込むフォルダの外にあるファイルから、何かがこれを読み込みました。そのため、Macを再起動するとmacOSはこれを忘れます。そのファイルは上に表示されています。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS가 시동 시 읽는 폴더 밖의 파일에서 무언가가 이 항목을 로드했으므로, Mac을 재시동하면 macOS가 이 항목을 잊습니다. 파일은 위에 표시되어 있습니다."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Iets heeft dit geladen uit een bestand buiten de mappen die macOS bij het opstarten leest, dus macOS vergeet het als de Mac opnieuw opstart. Het bestand staat hierboven."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Coś wczytało tę rzecz z pliku spoza folderów, które macOS odczytuje podczas startu systemu, więc macOS zapomni o niej, gdy Mac uruchomi się ponownie. Ten plik jest pokazany powyżej."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Algo carregou este item de um arquivo fora das pastas que o macOS lê na inicialização, então o macOS o esquece quando o Mac é reiniciado. O arquivo aparece acima."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Ceva l‑a încărcat dintr‑un fișier aflat în afara dosarelor pe care macOS le citește la pornire, așa că macOS îl uită când Mac‑ul repornește. Fișierul este afișat mai sus."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Что-то загрузило этот объект из файла вне папок, которые macOS читает при загрузке Mac, поэтому macOS забудет о нем, когда Mac перезагрузится. Файл показан выше."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Något läste in det här från en fil utanför de mappar som macOS läser vid systemstart, så macOS glömmer det när datorn startas om. Filen visas ovan."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Bu, macOS’in Mac açıldığında okuduğu klasörlerin dışındaki bir dosyadan yüklendi, bu yüzden macOS, Mac yeniden başladığında onu unutur. Dosya yukarıda gösteriliyor."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Щось завантажило цей елемент з файлу поза папками, які macOS читає під час запуску системи, тож macOS забуває про нього, коли Mac перезапускається. Файл показано вище."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "某个程序从macOS在启动时读取的文件夹之外的文件载入了此项,因此Mac重新启动时,macOS会忘记它。该文件显示在上方。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "有東西從macOS在開機時讀取的檔案夾以外的檔案載入了此項目,因此Mac重新開機時macOS就會忘記它。該檔案顯示於上方。"
+ }
+ }
+ }
+ },
"Something with this identifier is running now" : {
"localizations" : {
"cs" : {
diff --git a/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItem.swift b/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItem.swift
index c45d56db..fc19e001 100644
--- a/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItem.swift
+++ b/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItem.swift
@@ -10,7 +10,11 @@ public struct BackgroundItem: Sendable, Hashable, Identifiable {
public enum Source: Sendable, Hashable {
case userLibrary
case systemLibrary
+ /// Registered or submitted by an app, and known only while it is loaded.
case app
+ /// Loaded from a file outside the folders launchd reads by itself, and known only while it is loaded: launchd
+ /// forgets it at the next logout or restart.
+ case otherFile
}
public enum State: Sendable, Hashable {
@@ -59,5 +63,9 @@ public struct BackgroundItem: Sendable, Hashable, Identifiable {
public var removalRequiresPrivileges: Bool { source == .systemLibrary }
- public var canMoveToTrash: Bool { source != .app && plistURL != nil && !usesALabelOfMacOS }
+ /// True for a job Peel sees only while it is loaded, so once stopped it would leave the list and could not be
+ /// started again from here.
+ public var isSeenOnlyWhileLoaded: Bool { source == .app || source == .otherFile }
+
+ public var canMoveToTrash: Bool { !isSeenOnlyWhileLoaded && plistURL != nil && !usesALabelOfMacOS }
}
diff --git a/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItems.swift b/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItems.swift
index c97b6af7..5fbc6fd8 100644
--- a/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItems.swift
+++ b/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItems.swift
@@ -35,12 +35,12 @@ public enum BackgroundItems {
var results: [BackgroundItem] = []
for _ in 0..<concurrentDetailQueries {
guard let next = pending.next() else { break }
- group.addTask { await appSubmittedItem(next, ownership: ownership, loaded: loaded) }
+ group.addTask { await appSubmittedItem(next, ownership: ownership, loaded: loaded, exclusions: exclusions) }
}
while let result = await group.next() {
if let result { results.append(result) }
if !Task.isCancelled, let next = pending.next() {
- group.addTask { await appSubmittedItem(next, ownership: ownership, loaded: loaded) }
+ group.addTask { await appSubmittedItem(next, ownership: ownership, loaded: loaded, exclusions: exclusions) }
}
}
return results
@@ -142,33 +142,52 @@ public enum BackgroundItems {
private static func appSubmittedItem(
_ candidate: (label: String, kind: BackgroundItem.Kind, target: String),
ownership: BackgroundItemOwnership,
- loaded: Loaded
+ loaded: Loaded,
+ exclusions: Exclusions
) async -> BackgroundItem? {
let details = Launchctl.parseDetails(await Launchctl.run(["print", candidate.target]).output)
+ return undeclaredItem(candidate, details: details, ownership: ownership, loaded: loaded, exclusions: exclusions)
+ }
+
+ /// The item for a loaded job no file in the three folders declares, from what `launchctl print` said of it: one
+ /// an app registered or submitted, named by its owner when Peel can tell it, or one something loaded from a file
+ /// anywhere else, which launchd forgets at the next logout or restart. A job macOS loaded from its own folders is
+ /// not an item, and neither is a file the user excluded.
+ static func undeclaredItem(
+ _ candidate: (label: String, kind: BackgroundItem.Kind, target: String),
+ details: Launchctl.JobDetails,
+ ownership: BackgroundItemOwnership,
+ loaded: Loaded,
+ exclusions: Exclusions
+ ) -> BackgroundItem? {
let isSubmittedByApp = details.path?.hasPrefix("(submitted by") == true
&& details.program.map { !PathComponents.isPath($0, inside: "/System") } == true
- guard details.managedBy == serviceManagement || isSubmittedByApp else { return nil }
+ let isAnApps = details.managedBy == serviceManagement || isSubmittedByApp
let path = details.path.flatMap { $0.hasPrefix("/") ? URL(filePath: $0) : nil }
+ let isMacOSs = path.map { file in
+ ["/System", "/Library/Apple"].contains { PathComponents.isPath(file.path(percentEncoded: false), inside: $0) }
+ } ?? false
+ guard isAnApps || (path != nil && !isMacOSs), path.map(exclusions.excludes) != true else { return nil }
let job = path.flatMap(JobDefinition.init(contentsOf:))
let program = details.program ?? job?.program
- guard let owner = ownership.owner(
+ let owner = ownership.owner(
label: candidate.label,
registeredBy: details.parentBundleIdentifier,
associated: job?.associated ?? [],
program: program
- ) else { return nil }
+ )
return BackgroundItem(
label: candidate.label,
kind: candidate.kind,
- source: .app,
+ source: isAnApps ? .app : .otherFile,
plistURL: path,
program: program,
runsAtLoad: job?.runsAtLoad ?? false,
keepsAlive: job?.keepsAlive ?? false,
- ownerBundleIdentifier: owner.bundleIdentifier,
- ownerName: owner.name,
- isOwnerInstalled: owner.isInstalled,
+ ownerBundleIdentifier: owner?.bundleIdentifier,
+ ownerName: owner?.name,
+ isOwnerInstalled: owner?.isInstalled ?? false,
isOrphan: ownership.isOrphan(label: candidate.label, program: program, owner: owner),
state: loaded.state(of: candidate.label, candidate.kind),
isDisabled: loaded.override(of: candidate.label, candidate.kind) ?? false
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/BackgroundItemActionsTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/BackgroundItemActionsTests.swift
index 5f29b40d..c9fa74e6 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/BackgroundItemActionsTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/BackgroundItemActionsTests.swift
@@ -156,6 +156,30 @@ struct DeclaredBackgroundItemsTests {
#expect(BackgroundItemActions.refusal(for: own) == nil)
}
+ /// A loaded job no file in the three folders declares is listed when an app registered or submitted it, whether
+ /// or not Peel can name that app, and when something loaded it from a file anywhere else, which launchd forgets at
+ /// the next logout or restart. A job macOS loaded from its own folders is not, and neither is an excluded file.
+ @Test func listsAJobLoadedFromElsewhereOrWithNoOwner() throws {
+ let directory = try TemporaryDirectory()
+ let ownership = BackgroundItemOwnership(installedApps: [])
+ let stray = try directory.file("home/Desktop/org.example.stray.plist", contents: job("org.example.stray", program: "/bin/sh"))
+ func item(_ label: String, _ details: Launchctl.JobDetails, exclusions: Exclusions = .none) -> BackgroundItem? {
+ BackgroundItems.undeclaredItem((label, .agent, "gui/501/\(label)"), details: details, ownership: ownership, loaded: .init(), exclusions: exclusions)
+ }
+
+ let loadedElsewhere = try #require(item("org.example.stray", .init(path: stray.path(percentEncoded: false), program: "/bin/sh")))
+ #expect(loadedElsewhere.source == .otherFile)
+ #expect(loadedElsewhere.plistURL?.lastPathComponent == "org.example.stray.plist")
+ #expect(!loadedElsewhere.canMoveToTrash)
+
+ let nobodys = try #require(item("org.example.nobody", .init(path: "(submitted by tool[42])", program: "/usr/local/bin/org.example.nobody")))
+ #expect(nobodys.source == .app)
+ #expect(nobodys.ownerBundleIdentifier == nil)
+
+ #expect(item("com.openssh.ssh-agent", .init(path: "/System/Library/LaunchAgents/com.openssh.ssh-agent.plist", program: "/usr/bin/ssh-agent")) == nil)
+ #expect(item("org.example.stray", .init(path: stray.path(percentEncoded: false), program: "/bin/sh"), exclusions: Exclusions(paths: [stray])) == nil)
+ }
+
/// One label declared in two folders is two files, and each row opens its own.
@Test func keepsTwoFilesThatDeclareOneLabelApart() throws {
let directory = try TemporaryDirectory()
diff --git a/Peel/Views/BackgroundItems/BackgroundItemDetailView.swift b/Peel/Views/BackgroundItems/BackgroundItemDetailView.swift
index 36d68e9a..a1fe7f50 100644
--- a/Peel/Views/BackgroundItems/BackgroundItemDetailView.swift
+++ b/Peel/Views/BackgroundItems/BackgroundItemDetailView.swift
@@ -113,6 +113,18 @@ struct BackgroundItemDetailView: View {
}
}
+ if item.source == .otherFile {
+ Section {
+ Notice(
+ title: Text("Loaded from a file elsewhere"),
+ detail: item.kind == .daemon
+ ? Text("Something loaded this from a file outside the folders macOS reads at startup, so macOS forgets it when the Mac restarts. The file is shown above.")
+ : Text("Something loaded this from a file outside the folders macOS reads at login, so macOS forgets it when you log out. The file is shown above."),
+ kind: .note
+ ) {}
+ }
+ }
+
if item.state == .unknown {
Section {
Notice(
@@ -285,9 +297,9 @@ struct BackgroundItemDetailView: View {
private var ownControls: some View {
Group {
- // No Start or Stop for a job an app registered. Peel sees it only while it is loaded, so once stopped
- // it would leave the list, and Peel could not start it again. System Settings also offers only a switch.
- if item.source != .app {
+ // No Start or Stop for a job Peel sees only while it is loaded: once stopped it would leave the list,
+ // and Peel could not start it again. For an app's job, System Settings also offers only a switch.
+ if !item.isSeenOnlyWhileLoaded {
let isRunning = if case .running = item.state { true } else { false }
Button(isRunning ? "Stop" : "Start", systemImage: isRunning ? "stop.fill" : "play.fill") {
Task { await backgroundItems.perform(isRunning ? .stop : .start, on: item) }