Quick Fix for Disk wasn’t ejected (Mac)

When one or more of your files are open on a mounted volume, you get this error.

If you’re tired of seeing the error “Disk wasn’t ejected because one or more programs may be using it.” while ejecting your drives then this article is exactly for you.

There are several sources for this problem. Here I list a few common ones, how to identify the problem and how to fix it.

Fire up a terminal and type in the following command (you will need an administrator password):

sudo lsof /Volumes/yourDiskName

This command will give the information on which program(s)/process(es) is/(are) reading/writing to which file(s) on your disk. You can eliminate the processes hogging your files one by one and you should have solved your problem.

Most common problems:

  1. Spotlight indexing:

    If you see the process name like “mds_store”, it is spotlight that is indexing the contents of the drive (which might take long.)

    You have 2 options:

    a. if you want spotlight to index the drive, then you have to wait it out.

    b. Otherwise, if you want it to stop & not bother you again, you can easily ask Spotlight to “ignore” your disk by going to:

     → System Preferences → Spotlight → Privacy → Add/Drag the disk here.

  2. QuickLook preview:

    QuickLook is a fantastic utility (Try it: hit spacebar on any file selected in the finder and it’ll show you a quick preview of the file. Works with audio, video, PDF, images, documents, and many others). One of the main reasons why I can’t switch over to other operating system. However, it can get stuck on one (or more) of your files despite you having closed the quicklook popup window.

    To identify if Quicklook is causing the problem you can run the following command and check if it lists QuickLook under COMMAND:

    sudo lsof /Volumes/yourDiskName
    

    Here is an example of QuickLook blocking a couple of files:

    Here you can see details of the processes accessing files on your disk.

    Running the following command in the terinal fixes it. The commands kill the QuickLookUI service and resets the QuickLook Server and the generator cache of all QuickLook client’s.

    /usr/bin/killall -KILL QuickLookUIService && sudo qlmanage -r  
    

    Ejecting the disk should function normally now. Running sudo lsof /Volumes/yourDiskNameagain should display that no programs are accessing your files and blocking the process of ejecting the drive/volume.

Previous