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.

Say how to free an input method in use

Țugui Dragoș5f9d27891baf
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index 7f4bf49c..0a8e29f6 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -65287,6 +65287,112 @@
}
}
},
+ "It is in use as an input source. In System Settings > Keyboard > Text Input, click Edit beside Input Sources, select it and click Remove, then try again." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Používá se jako vstupní zdroj. V Nastavení systému > Klávesnice > Zadání textu klikněte na tlačítko Upravit vedle položky Vstupní zdroje, vyberte ho, klikněte na Odebrat a zkuste to znovu."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Es wird als Eingabequelle verwendet. Klicke unter „Systemeinstellungen“ > „Tastatur“ > „Texteingabe“ neben „Eingabequellen“ auf „Bearbeiten“, wähle es aus und klicke auf „Entfernen“. Versuche es dann erneut."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Está en uso como fuente de entrada. En Ajustes del Sistema > Teclado > Entrada de texto, haz clic en Editar junto a Fuentes de entrada, selecciónalo, haz clic en Eliminar y vuelve a intentarlo."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Il est utilisé comme méthode de saisie. Dans Réglages Système > Clavier > Entrée de texte, cliquez sur Modifier à côté de « Méthodes de saisie », sélectionnez-le et cliquez sur Supprimer, puis réessayez."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "È in uso come sorgente di input. In Impostazioni di Sistema > Tastiera > Immetti testo, fai clic su Modifica accanto a “Sorgenti di input”, selezionalo e fai clic su Rimuovi, poi riprova."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "入力ソースとして使用中です。“システム設定”>“キーボード”>“テキスト入力”で、“入力ソース”の横にある“編集”をクリックし、これを選択して“削除”をクリックしてから、やり直してください。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "입력 소스로 사용 중입니다. 시스템 설정 > 키보드 > 텍스트 입력에서 ‘입력 소스’ 옆의 ‘편집’을 클릭하고 이 입력 소스를 선택한 후 ‘제거’를 클릭한 다음 다시 시도하십시오."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Het wordt gebruikt als invoerbron. Klik in Systeeminstellingen > Toetsenbord > Tekstinvoer op 'Wijzig' naast 'Invoerbronnen', selecteer het, klik op 'Verwijder' en probeer het opnieuw."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Jest używana jako źródło wprowadzania. W Ustawieniach systemowych > Klawiatura > Wprowadzanie tekstu kliknij w przycisk Edycja obok pozycji Źródła wprowadzania, zaznacz ją, kliknij w Usuń i spróbuj ponownie."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Está em uso como layout de teclado. Em Ajustes do Sistema > Teclado > Entrada de Texto, clique em Editar ao lado de Layouts de Teclado, selecione-o, clique em Remover e tente novamente."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Este utilizat ca sursă de introducere. În Configurări sistem > Tastatură > Introducere text, faceți clic pe butonul Editare de lângă „Surse de introducere”, selectați‑l și faceți clic pe Eliminați, apoi încercați din nou."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Объект используется как источник ввода. В разделе «Системные настройки» > «Клавиатура» > «Ввод текста» нажмите кнопку «Изменить» рядом с пунктом «Источники ввода», выберите этот объект и нажмите «Удалить», а затем повторите попытку."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Den används som inmatningskälla. Klicka på Redigera bredvid Inmatningskällor i Systeminställningar > Tangentbord > Textinmatning, markera den, klicka på Ta bort och försök sedan igen."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Bir giriş kaynağı olarak kullanılıyor. Sistem Ayarları > Klavye > Metin Girişi bölümünde Giriş Kaynakları’nın yanındaki Düzenle’yi tıklayın, onu seçip Sil’i tıklayın, ardından yeniden deneyin."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Він використовується як джерело вводу. У розділі Системні параметри > Клавіатура > Введення тексту натисніть «Змінити» поруч із пунктом «Джерела вводу», виберіть його, натисніть «Вилучити» і спробуйте ще раз."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "它正被用作输入法。请在“系统设置”>“键盘”>“文字输入”中,点按“输入法”旁边的“编辑”,选择它并点按“移除”,然后重试。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "它正被用作輸入方式。請在「系統設定」>「鍵盤」>「文字輸入」中,按一下「輸入方式」旁邊的「編輯」,選取它並按一下「移除」,然後再試一次。"
+ }
+ }
+ }
+ },
"It is in use by %@ in another user’s account on this Mac. Quit it in that account, then try again." : {
"localizations" : {
"cs" : {
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
index e9d82da4..d74a6785 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
@@ -482,6 +482,8 @@ extension TrashFailure.Reason {
"in use by \(processes.map(Output.plain).joined(separator: ", ")) in another user's account on this Mac; quit it in that account, then try again"
case .heldByABuildTool(let tools):
"in use by \(tools.map(Output.plain).joined(separator: ", ")); run \(BuildDaemon.stopCommands(for: tools).map { "`\($0)`" }.joined(separator: " and ")), then try again"
+ case .inUseAsAnInputSource:
+ "in use as an input source; in System Settings > Keyboard > Text Input, click Edit beside Input Sources, select it and click Remove, then try again"
case .inUseByMacOS(let processes): "in use by macOS (\(processes.map(Output.plain).joined(separator: ", ")))"
case .attachedDiskImage: "a disk image open right now; eject it, then try again"
case .failed(let message): Output.plain(message)
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/OpenFiles.swift b/Packages/PeelCore/Sources/PeelCore/Removal/OpenFiles.swift
index ba4ad863..704dca84 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/OpenFiles.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/OpenFiles.swift
@@ -93,7 +93,13 @@ struct OpenFiles {
let names = PathComponents.of(PathPattern.canonical(url).path(percentEncoded: false))
if !lettingItsProgramsRun, let excludedProgram, excludedProgram.starts(with: names) { return .peelRunsFromIt }
if attachedImages.contains(where: { $0.starts(with: names) }) { return .attachedDiskImage }
- return Self.refusal(heldBy: holding(url, lettingItsProgramsRun: lettingItsProgramsRun).map { file in
+ let holding = holding(url, lettingItsProgramsRun: lettingItsProgramsRun)
+ // An input method runs from its own bundle while it is one of the input sources, which System Settings removes.
+ if Self.isAnInputMethod(url), !holding.isEmpty,
+ holding.allSatisfy({ $0.hold == .runs && $0.owner == .thisAccount }) {
+ return .inUseAsAnInputSource
+ }
+ return Self.refusal(heldBy: holding.map { file in
Holder(
process: file.process, owner: file.owner,
isMacOSsOwn: programs[file.pid].map(Self.isMacOSsOwn) ?? false, daemon: file.daemon
@@ -101,6 +107,14 @@ struct OpenFiles {
})
}
+ /// Whether `url` is an input method installed for the Mac or for this account: an item right in the Input Methods
+ /// folder of a Library.
+ static func isAnInputMethod(_ url: URL) -> Bool {
+ let folder = url.deletingLastPathComponent()
+ return folder.lastPathComponent == LibraryFolder.inputMethods.rawValue
+ && folder.deletingLastPathComponent().lastPathComponent == "Library"
+ }
+
struct Holder {
let process: String
let owner: Owner
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift b/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift
index ae53cace..a53c5742 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift
@@ -94,6 +94,8 @@ public struct TrashFailure: Sendable, Hashable {
case openForAnotherUser(by: [String])
/// Only build tools' daemons hold it, which the tools' own commands stop (`BuildDaemon`).
case heldByABuildTool(by: [String])
+ /// It is an input method running as one of this account's input sources, which System Settings removes.
+ case inUseAsAnInputSource
/// Only macOS's own programs hold it, and nobody quits those.
case inUseByMacOS(by: [String])
/// It is a disk image attached right now, or a folder holding one, which macOS holds open until it is ejected.
@@ -118,13 +120,13 @@ extension TrashFailure.Reason {
case .historyUnreadable, .historyCannotBeWritten, .needsHelper: false
case .guarded, .changedSinceScan, .claimedSinceScan, .lastCopy, .notPermitted, .locked, .movedWithoutATrace,
.somethingElseMoved, .heldOpen, .peelRunsFromIt, .heldByAnotherAccount, .openForAnotherUser,
- .heldByABuildTool, .inUseByMacOS, .attachedDiskImage, .failed: true
+ .heldByABuildTool, .inUseAsAnInputSource, .inUseByMacOS, .attachedDiskImage, .failed: true
}
}
var isHeldByPrograms: Bool {
switch self {
- case .heldOpen, .heldByAnotherAccount, .openForAnotherUser, .heldByABuildTool: true
+ case .heldOpen, .heldByAnotherAccount, .openForAnotherUser, .heldByABuildTool, .inUseAsAnInputSource: true
default: false
}
}
@@ -149,6 +151,7 @@ extension TrashFailure.Reason {
case .heldByAnotherAccount: "held-by-another-account"
case .openForAnotherUser: "open-for-another-user"
case .heldByABuildTool: "held-by-a-build-tool"
+ case .inUseAsAnInputSource: "in-use-as-an-input-source"
case .inUseByMacOS: "in-use-by-macos"
case .attachedDiskImage: "attached-disk-image"
case .failed: "failed"
@@ -192,6 +195,7 @@ extension TrashFailure.Reason {
self = .openForAnotherUser(by: (detail ?? "").split(separator: "\n").map(String.init))
case "held-by-a-build-tool":
self = .heldByABuildTool(by: (detail ?? "").split(separator: "\n").map(String.init))
+ case "in-use-as-an-input-source": self = .inUseAsAnInputSource
case "in-use-by-macos": self = .inUseByMacOS(by: (detail ?? "").split(separator: "\n").map(String.init))
case "attached-disk-image": self = .attachedDiskImage
case "failed": self = .failed(detail ?? "")
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/OpenFilesTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/OpenFilesTests.swift
index e47f9bbf..f5d5c368 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/OpenFilesTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/OpenFilesTests.swift
@@ -177,6 +177,21 @@ struct OpenFilesTests {
#expect(refusal == .heldByABuildTool(by: ["Gradle"]))
}
+ @Test func anInputSourceInUseIsRemovedInSystemSettings() throws {
+ let directory = try TemporaryDirectory()
+ let programs = try directory.runningPrograms([
+ "home/Library/Input Methods/Example.app/Contents/MacOS/example",
+ "home/Library/Application Support/Example.app/Contents/MacOS/example",
+ ])
+ defer { programs.forEach { $0.terminate() } }
+ let files = OpenFiles()
+
+ let inputSource = directory.url.appending(path: "home/Library/Input Methods/Example.app")
+ let elsewhere = directory.url.appending(path: "home/Library/Application Support/Example.app")
+ #expect(files.refusal(of: inputSource, lettingItsProgramsRun: false) == .inUseAsAnInputSource)
+ #expect(files.refusal(of: elsewhere, lettingItsProgramsRun: false) == .heldOpen(by: ["example"]))
+ }
+
@Test func aScriptAProgramRunsHoldsTheFolderItRunsFrom() throws {
let directory = try TemporaryDirectory()
let script = try directory.file("home/.npm/_npx/0123abcd/node_modules/.bin/server")
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/RefusalLogTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/RefusalLogTests.swift
index f45deeeb..f600e1e3 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/RefusalLogTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/RefusalLogTests.swift
@@ -233,7 +233,7 @@ struct RefusalLogTests {
.guarded(nil), .changedSinceScan, .claimedSinceScan, .lastCopy, .notPermitted, .needsHelper,
.movedWithoutATrace, .somethingElseMoved(named: "x 2"), .historyUnreadable, .historyCannotBeWritten,
.heldOpen(by: ["Figma Agent", "java"]), .peelRunsFromIt, .heldByAnotherAccount(by: ["CtxHelper"]),
- .openForAnotherUser(by: ["Spotify"]), .heldByABuildTool(by: ["Gradle"]),
+ .openForAnotherUser(by: ["Spotify"]), .heldByABuildTool(by: ["Gradle"]), .inUseAsAnInputSource,
.inUseByMacOS(by: ["geod", "appleaccountd"]), .failed("x"),
] + GuardRefusal.allCases.map { .guarded($0) }
diff --git a/Peel/Views/Presentation.swift b/Peel/Views/Presentation.swift
index 187af893..97b1afb6 100644
--- a/Peel/Views/Presentation.swift
+++ b/Peel/Views/Presentation.swift
@@ -195,6 +195,8 @@ extension TrashFailure.Reason {
String(localized: "It is in use by \(processes.formatted(.list(type: .and))) in another user’s account on this Mac. Quit it in that account, then try again.", bundle: bundle)
case .heldByABuildTool(let tools):
String(localized: "It is in use by \(tools.formatted(.list(type: .and))). Run \(BuildDaemon.stopCommands(for: tools).map { "`\($0)`" }.formatted(.list(type: .and))), then try again.", bundle: bundle)
+ case .inUseAsAnInputSource:
+ String(localized: "It is in use as an input source. In System Settings > Keyboard > Text Input, click Edit beside Input Sources, select it and click Remove, then try again.", bundle: bundle)
case .inUseByMacOS(let processes):
String(localized: "macOS is using it right now, through \(processes.formatted(.list(type: .and))), so it stays where it is.", bundle: bundle)
case .attachedDiskImage: