Skip to content

Commit c9f2fef

Browse files
rowildclaude
andcommitted
Merge feature/finder-everywhere — Finder menu on Desktop, all folders, and drives
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 parents 8006ec5 + 3f2ed78 commit c9f2fef

12 files changed

Lines changed: 200 additions & 159 deletions

‎AGENTS.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,12 @@ The following records earlier approaches. For current behavior, authorization, a
253253

254254
Read [DEVELOPER.md](DEVELOPER.md) before changing signing, App Groups, installation, file creation, or monitored folders. It is the current source for those contracts and their verified evidence.
255255

256-
- Host and extension share `MoreMenu/Shared` sources: document catalog, preferences, file creation, target resolution, and home-directory policy.
256+
- Host and extension share `MoreMenu/Shared` sources: document catalog, preferences, file creation, target resolution, and monitored-volume policy.
257257
- Both products use the App Group `QN24ZH7M6W.GMX.MoreMenu`, authorized by the matching certificate-backed signing Team ID. Local builds reject ad-hoc signing.
258258
- Preserve consent during upgrades. Migrate the two legacy preferences through the signed host import command; retain old data and never read the unauthorized legacy group from the extension.
259259
- Use exclusive file creation and retry only filename collisions. Preserve existing contents and propagate other failures.
260-
- Monitor filtered visible top-level home folders once at initialization. Exclude home/filesystem roots, Library, Applications, and packages. External volumes remain out of scope.
261-
- Desktop-specific behavior is deferred at the user's request. Keep the existing fallback unchanged until that investigation resumes.
260+
- Monitor `/` plus every visible mounted volume, and update the set on mount, unmount, and rename. Release a volume on `willUnmount`. See DEVELOPER.md for the 2026-10-03 evidence (Desktop background and home-rooted windows need `/`).
261+
- Build the menu without file-metadata reads; resolve the destination only in the menu action.
262262
- Validate with `./scripts/test.sh`, then inspect a signed Release build. Reboot/Finder UI behavior requires live manual validation; passing unit tests alone is insufficient.
263263
- The app opens Finder's extension-management interface through `FIFinderSyncController.showExtensionManagementInterface()`. Settings paths vary by macOS version.
264264

‎CHANGELOG.md‎

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,37 @@
22

33
## Unreleased
44

5+
### Added
6+
7+
- **The menu now works everywhere in Finder:** on the Desktop background, in windows rooted at the home folder, in any folder on the startup disk, and on external and network drives. The extension monitors `/` plus every mounted volume and updates the set when a drive is mounted, renamed, or unmounted. A drive is released before it unmounts, so MoreMenu cannot block ejecting it.
8+
- Each Finder menu request is logged with its menu kind and target, so a missing menu can be told apart from a skipped callback.
9+
510
### Fixed
611

7-
- Authorize shared preferences with the signing Team-ID-prefixed App Group. The installed app's repeated AppData prompt was traced to an unauthorized `group.GMX.MoreMenu` container, despite Apple Development signing. This supersedes the earlier signing-only diagnosis below.
12+
- **Repeated privacy prompts.** Three causes were found and removed:
13+
- Shared preferences now use the Team-ID-prefixed App Group `QN24ZH7M6W.GMX.MoreMenu`, which the signing certificate authorizes. The old `group.GMX.MoreMenu` container was unauthorized, so macOS asked "access data from other apps" again for every extension process.
14+
- Stored privacy answers were bound to the hashes of old ad-hoc builds. Answers given to a certificate-signed build stay valid across rebuilds signed with the same certificate.
15+
- `test.sh` unregisters its unsigned test build from Launch Services and PlugInKit. Stray copies with the same bundle IDs could be loaded by Finder under a different code identity.
16+
- A right-click alone can no longer start a folder-privacy check. The menu is built without reading file metadata; the destination folder is resolved only after a command is chosen.
17+
- No menu in the Documents column of a home-rooted window, and none on the Desktop background. Finder did not consult the extension there while it monitored only top-level home folders.
818
- Create new files exclusively and retry filename collisions without replacing existing data.
919
- Reject unresolved target metadata rather than creating in a guessed parent folder; show creation errors.
1020
- Preserve consent and preferences during local upgrades, verify staged signatures, and restore the previous app if migration or registration fails.
1121

1222
### Changed
1323

14-
- Share one file-type catalog and preference contract between app and extension.
24+
- The extension sandbox allows writes on every volume (`temporary-exception.files.absolute-path.read-write = /`, previously home only). Read-only locations report an error after the click instead of hiding the menu.
25+
- Full Disk Access for MoreMenu.app is the recommended setup. With it enabled, the extension created files on the Desktop and in Downloads without any prompt (verified on macOS 26.6.2). Without it, macOS asks once per location type.
26+
- This reverses the 1.2.2 narrowing below. That change was based on a misdiagnosis of the AppData prompt, whose real cause was the unauthorized App Group.
27+
- Share one file-type catalog, preference contract, and monitored-volume policy between app and extension.
1528
- Add behavioral Swift tests, installer/signature tests, a shared Xcode test scheme, and CI checks.
1629
- Require certificate-backed signing for local packages; public releases require Developer ID signing and notarization credentials.
1730
- Use the Finder Sync extension-management API for settings navigation and label file-type checkboxes for accessibility.
18-
- Desktop-specific behavior remains deferred.
31+
32+
### Not yet verified
33+
34+
- After a restart, that the "access data from other apps" prompt stays away while `/` is monitored.
35+
- On an external drive: adding the drive when it is connected, creating a file on it, and ejecting it.
1936

2037
## 1.2.2 - 2026-05-11
2138

‎DEVELOPER.md‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
./scripts/install-local.sh
99
```
1010

11-
`test.sh` runs script tests and standalone macOS unit tests. The tests compile the same Shared sources as the app and extension, without launching the host app or running the installer. The shared Xcode scheme also builds the app and extension to catch integration errors. Xcode 16.2 or later is required; the deployment target remains macOS 14.
11+
`test.sh` runs script tests and standalone macOS unit tests. The tests compile the same Shared sources as the app and extension, without launching the host app or running the installer. The shared Xcode scheme also builds the app and extension to catch integration errors. Xcode registers that unsigned build with Launch Services, so `test.sh` unregisters its build products on exit; otherwise Finder could load the test copy and TCC would see a different code identity. Xcode 16.2 or later is required; the deployment target remains macOS 14.
1212

1313
`build-app.sh` builds a universal Release app, signs the extension before its containing app, and verifies both signatures and entitlement sets. By default it selects an available Apple Development identity. Override with `MOREMENU_CODE_SIGN_IDENTITY`. It rejects ad-hoc signatures and signing teams that do not match the App Group. No app is installed by this command.
1414

@@ -21,7 +21,7 @@ Build/test output is under `.build/` by default. `MOREMENU_TEST_DERIVED_DATA` ov
2121
- `MoreMenu/Shared/DocumentKind.swift`: the 19 persistent file-type identifiers, UI/menu titles, extensions, categories, and initial contents.
2222
- `Shared/MenuPreferences.swift`: the shared defaults contract and idempotent legacy import.
2323
- `Shared/DocumentFileCreator.swift`: exclusive filename creation with numbered retries.
24-
- `Shared/HomeDirectoryScope.swift`: home-boundary and monitored-directory policy.
24+
- `Shared/FinderMonitoringScope.swift`: the monitored set — the boot volume root plus every mounted volume.
2525
- `Shared/TargetDirectoryResolver.swift`: file-versus-folder resolution; failed metadata reads propagate as errors.
2626
- `MoreMenu/SettingsStore.swift`: observable settings shared by all settings windows.
2727
- `MoreMenuExtension/FinderSync.swift`: Finder callbacks, target acquisition, menu presentation, file opening, and error feedback.
@@ -44,15 +44,19 @@ Sources: [App Group authorization](https://developer.apple.com/documentation/xco
4444

4545
### Sandbox write capability
4646

47-
The extension retains `com.apple.security.temporary-exception.files.home-relative-path.read-write = ["/"]`. In this entitlement, `/` means the user's home. The host has no broad file-write entitlement. External volumes remain out of scope. This task does not expand write capability or add Apple Events permissions.
47+
The extension uses `com.apple.security.temporary-exception.files.absolute-path.read-write = ["/"]`, so the sandbox allows writes on every volume. POSIX permissions and TCC still apply. The host has no file-write entitlement. App extensions must be sandboxed, so this temporary exception is the sandbox capability for local and Developer ID builds; it is not suitable for the Mac App Store.
4848

4949
### Folder privacy and Finder monitoring
5050

5151
Sandbox capability does not override macOS privacy decisions. Normal folder-access permissions and App Group authorization must be diagnosed separately.
5252

53-
Finder monitoring remains limited to visible top-level home subfolders, excluding `Library`, `Applications`, and packages. Set `directoryURLs` exactly once at extension initialization, using `HomeDirectoryScope.monitoredDirectoryURLs()`. Keep this conservative policy; the old notes attributing every AppData prompt to monitoring scope are not sufficient evidence to change it.
53+
Finder consults a Finder Sync extension only for clicks inside its monitored folders. On 2026-10-03 (macOS 26.6.2), with only top-level home folders monitored, Finder did not call `menu(for:)` for the Desktop background or for a column-view window rooted at the home folder. BetterZip, whose extension monitors all mounted volumes, appeared in both menus.
5454

55-
`FinderSyncInvariantTests` exercises the actual folder-selection policy against temporary filesystem fixtures and retains one structural guard for the single registration assignment.
55+
The extension therefore monitors `/` plus every visible mounted volume (`FinderMonitoringScope.directoryURLs`). `/` does not cover other mounts, so each volume is listed explicitly. The set is recomputed on mount, unmount, and rename. A volume is released on `willUnmount`, so Finder Sync cannot block ejecting it.
56+
57+
The May 2026 note that blamed `/` monitoring for the AppData prompt predates the App Group fix. Confirm with a reboot test that the prompt stays away.
58+
59+
`FinderSyncInvariantTests` covers the monitored-set policy and guards two structural rules: one `directoryURLs` assignment, and no file-metadata reads while building the menu.
5660

5761
## Preference migration
5862

@@ -78,11 +82,11 @@ Files use `untitled.ext`, `untitled_0001.ext`, and subsequent numbers. Rich text
7882

7983
[Apple's exclusive-write documentation](https://developer.apple.com/documentation/foundation/nsdata/writingoptions/withoutoverwriting)
8084

81-
## Desktop work is deferred
85+
## Desktop
8286

83-
Desktop background and cloud-managed Desktop behavior are explicitly outside this patch. The existing AppleScript insertion-location fallback is retained; its missing Apple Events sandbox authorization is a known limitation, not a supported Desktop guarantee. Do not broaden monitored roots or add automation entitlements as part of these reliability fixes.
87+
`menu(for:)` logs the menu kind and the targeted URL. No log line for a right-click means Finder did not consult the extension. A line with `target=nil` means MoreMenu returned an empty menu. For a desktop icon, Finder reported `~/Desktop` as the target.
8488

85-
For the later investigation, log whether Finder calls `menu(for:)`, the menu kind, and whether a target URL exists. Distinguish callback suppression from MoreMenu returning an empty menu before proposing a fix.
89+
The AppleScript insertion-location fallback cannot work: the extension lacks Apple Events entitlements, and tccd logs that refusal.
8690

8791
## Settings navigation
8892

@@ -119,7 +123,7 @@ The workflow uses a temporary keychain and removes its signing material afterwar
119123
1. Run `./scripts/test.sh`; include concurrent creation, preservation, RTF, settings migration, scope policy, signing rejection, and installer rollback checks.
120124
2. Build and verify a signed app. Inspect both products' Team ID, App Group, sandbox entitlement, and hardened runtime.
121125
3. After an actual local upgrade, confirm prior selections survive and only the intended installed extension is used.
122-
4. Test file creation and errors inside supported Finder folders, and verify out-of-home locations have no commands.
126+
4. Test file creation on the Desktop background, in home-rooted windows, and on an external volume. Check the error for a read-only location, and confirm that ejecting a drive still works.
123127
5. Relaunch the host/extension and reboot. Confirm the logs authorize the group and the repeated AppData prompt does not return. A successful build or one launch does not establish reboot behavior.
124128
6. Check the settings-management button and error dialog on macOS 14, 15, and 26 before claiming compatibility beyond compilation.
125129

‎MoreMenu/MoreMenuExtension/FinderSync.swift‎

Lines changed: 52 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,68 @@
44
//
55
// Created by Robert Wildling on 2026-04-07.
66
//
7-
// File creation is limited to the user home by the extension sandbox entitlement.
8-
// Shared preferences use a Team-ID-prefixed App Group authorized by the signer.
9-
// See DEVELOPER.md for the separate monitoring, sandbox, and TCC constraints.
7+
// The sandbox entitlement allows writes on every volume; POSIX permissions and
8+
// macOS privacy (TCC) still apply. Shared preferences use a Team-ID-prefixed
9+
// App Group authorized by the signer. See DEVELOPER.md for the constraints.
1010

1111
import Cocoa
1212
import FinderSync
1313
import OSLog
1414

1515
class FinderSync: FIFinderSync {
1616
private let logger = Logger(subsystem: "GMX.MoreMenu.MoreMenuExtension", category: "FinderSync")
17-
private let scope = HomeDirectoryScope.current
1817
private let fileCreator = DocumentFileCreator()
1918
private var currentMenuKind: FIMenuKind = .contextualMenuForContainer
19+
private var volumeObservers: [NSObjectProtocol] = []
2020

2121
override init() {
2222
super.init()
23-
FIFinderSyncController.default().directoryURLs = scope.monitoredDirectoryURLs()
23+
updateMonitoredDirectories()
24+
observeVolumeChanges()
25+
}
26+
27+
deinit {
28+
volumeObservers.forEach { NSWorkspace.shared.notificationCenter.removeObserver($0) }
29+
}
30+
31+
// MARK: - Monitored directories
32+
33+
private func observeVolumeChanges() {
34+
let center = NSWorkspace.shared.notificationCenter
35+
for name in [NSWorkspace.didMountNotification, NSWorkspace.didUnmountNotification, NSWorkspace.didRenameVolumeNotification] {
36+
volumeObservers.append(center.addObserver(forName: name, object: nil, queue: .main) { [weak self] _ in
37+
self?.updateMonitoredDirectories()
38+
})
39+
}
40+
volumeObservers.append(center.addObserver(forName: NSWorkspace.willUnmountNotification, object: nil, queue: .main) { [weak self] notification in
41+
let volume = notification.userInfo?[NSWorkspace.volumeURLUserInfoKey] as? URL
42+
self?.updateMonitoredDirectories(excluding: volume.map { [$0] } ?? [])
43+
})
44+
}
45+
46+
private func updateMonitoredDirectories(excluding unmountingVolumes: [URL] = []) {
47+
let mountedVolumes = FileManager.default.mountedVolumeURLs(includingResourceValuesForKeys: nil, options: [.skipHiddenVolumes]) ?? []
48+
let monitoredURLs = FinderMonitoringScope.directoryURLs(mountedVolumes: mountedVolumes, excluding: unmountingVolumes)
49+
FIFinderSyncController.default().directoryURLs = monitoredURLs
50+
logger.log("Monitoring: \(monitoredURLs.map(\.path).sorted().joined(separator: ", "), privacy: .public)")
2451
}
2552

2653
// MARK: - FIFinderSync overrides
2754

2855
override func menu(for menuKind: FIMenuKind) -> NSMenu {
56+
// No line logged for a right-click means Finder never consulted the extension.
57+
logger.log("menu(for:) kind=\(menuKind.rawValue, privacy: .public) target=\(FIFinderSyncController.default().targetedURL()?.path ?? "nil", privacy: .public)")
2958
guard menuKind == .contextualMenuForContainer || menuKind == .contextualMenuForItems else {
3059
return NSMenu(title: "")
3160
}
3261

3362
let menu = NSMenu(title: "")
3463
let enabledKinds = MenuPreferences.shared.activeKinds
3564

36-
guard let target = targetDirectory(for: menuKind), !enabledKinds.isEmpty else {
37-
return menu
38-
}
39-
40-
// Hide the menu in locations the sandbox entitlement can't reach:
41-
// filesystem root `/`, `/Volumes/*`, other users' homes, `/tmp`,
42-
// `/Applications`, etc. The user gets no false affordance for file
43-
// creation that would silently fail.
44-
guard scope.contains(target) else {
65+
// Path checks only. Reading metadata in a protected folder can raise a
66+
// privacy prompt on a mere right-click; folder resolution waits for the click.
67+
// Read-only locations surface as a creation error after the click.
68+
guard !enabledKinds.isEmpty, targetLocation(for: menuKind) != nil else {
4569
return menu
4670
}
4771

@@ -78,12 +102,6 @@ class FinderSync: FIFinderSync {
78102
return
79103
}
80104

81-
guard scope.contains(targetURL) else {
82-
logger.error("Refusing to create file outside user home: \(targetURL.path, privacy: .public)")
83-
NSSound.beep()
84-
return
85-
}
86-
87105
logger.log("Creating \(kind.fileExtension, privacy: .public) file in: \(targetURL.path, privacy: .public)")
88106

89107
do {
@@ -108,19 +126,26 @@ class FinderSync: FIFinderSync {
108126

109127
// MARK: - Target directory resolution
110128

111-
private func targetDirectory(for menuKind: FIMenuKind) -> URL? {
129+
/// The clicked item or folder, without touching the disk. Safe inside `menu(for:)`.
130+
private func targetLocation(for menuKind: FIMenuKind) -> URL? {
112131
if let targetedURL = FIFinderSyncController.default().targetedURL() {
113-
do {
114-
return try TargetDirectoryResolver.directory(for: targetedURL)
115-
} catch {
116-
logger.error("Could not resolve target directory: \(error.localizedDescription, privacy: .public)")
117-
return nil
118-
}
132+
return targetedURL
119133
}
120134
guard menuKind == .contextualMenuForContainer else { return nil }
121135
return currentInsertionLocation()
122136
}
123137

138+
/// Reads file metadata, so call it only from a menu action.
139+
private func targetDirectory(for menuKind: FIMenuKind) -> URL? {
140+
guard let location = targetLocation(for: menuKind) else { return nil }
141+
do {
142+
return try TargetDirectoryResolver.directory(for: location)
143+
} catch {
144+
logger.error("Could not resolve target directory: \(error.localizedDescription, privacy: .public)")
145+
return nil
146+
}
147+
}
148+
124149
private func currentInsertionLocation() -> URL? {
125150
let script = """
126151
tell application "Finder"

‎MoreMenu/MoreMenuExtension/MoreMenuExtension.entitlements‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<array>
99
<string>QN24ZH7M6W.GMX.MoreMenu</string>
1010
</array>
11-
<key>com.apple.security.temporary-exception.files.home-relative-path.read-write</key>
11+
<key>com.apple.security.temporary-exception.files.absolute-path.read-write</key>
1212
<array>
1313
<string>/</string>
1414
</array>

0 commit comments

Comments
 (0)