This post was written as part of the Kiroween 2026 hackathon (Resurrection category), for my entry PhantomTrace.
You finish a copy, you need the drive on another machine, and you drag it to the trash. Finder answers:
The disk wasn't ejected because one or more programs may be using it.
That is the whole message. It does not say which program, or which file.
I hit this constantly. At any moment I have several terminals open, a couple of editors, a coding agent or two, a preview app, a backup tool. Somewhere in that pile, one thing has a file open on the drive, or a shell is sitting in a folder on it. Finder will not tell me which. Quitting everything is not an option, because each of those apps holds work I have not saved or a session I would have to rebuild. So a five-second job (unplug the drive, use it elsewhere) turns into a hunt.
The usual workarounds all have a cost
lsof in a terminal and read the output. It works, but the output is dense, the right flags are easy to forget, and a path with spaces or odd characters makes it harder to read.kill -9. Quick, but risky. You can kill the wrong process, and an app that was mid-write can leave the drive in a bad state. What I wanted was the old Mac answer. In the System 7 and Mac OS 9 era there were small single-purpose utilities, such as What's Keeping Me?, that answered one question and got out of the way. The hackathon's Resurrection category asked for exactly that kind of revival, so I built one for modern macOS.
What PhantomTrace does
Right-click the stuck drive in Finder and choose the Quick Action "Why Can't I Eject?". PhantomTrace lists every process holding the volume: its name, process ID, user, whether it is a working-directory lock or an open file, and the exact file path. Diagnosis is always free. Nothing is touched until you choose.
If you want it fixed, there is a four-step pipeline, gentlest first, and you pick each step:
cd ~ to idle terminal shells. The terminal session survives. An idle shell sitting in a folder on the drive is a common blocker when you work in terminals. It rescans before and after every step, so it never acts on a stale picture. The point is that the thing keeping the drive busy is often a shell sitting in a folder, not an app doing real work, and you can fix that without closing anything.
A few rules are fixed in code: it never signals launchd, Finder, WindowServer or similar, never touches protected volumes, and never leaves the machine. There is no network code and no telemetry.
How Kiro shaped it
This is the part I would not have predicted before starting.
print in the core library and no networking APIs./private/var/vm slipped past the protected-volume check because a path-normalizing call rewrote it to /var/vm. I would not have written that test case by hand. Try it
The code is MIT licensed, with zero runtime dependencies, at https://github.com/iolaire/PhantomTrace. It builds with the Swift command line tools. The app is ad-hoc signed, not notarized, so build it from source. Use a throwaway disk image to try it, never a real backup drive. The Scripts/demo/setup-demo.sh script makes one with a held file and an idle shell. The demo video is at https://youtu.be/P3He7COqWzA.
Not done yet: notarization, and VoiceOver and Reduce Motion testing.
原文来源:dev.to