OSX - The volume can't be ejected because it's in use

I have more then once encountered osx messing up external drives because it gives you this error message "The volume can't be ejected because it's in use" . However looking in the dock and finder nothings open so what the heck is it's problem. If you turn of the computer or force eject it, it will render your drive useless and you probably have to repartition it.  You could try to hook it up to a windows pc, if it's exfat or ntfs partitioned it sometimes says "drive is damaged do you want to repair it" and it actually will repair it. Osx does the same but it'll scan forever and just say it damaged do you want to reformat it.

Turns out if you open the terminal and write "sudo lsof /Volumes/NameOfExternalDrive" it'll give you a list of programs and services tapping into the external drive. Apparently spotlight is the culprit and starts indexing external drives, which is guess is fine if it was a more permanently situated at the computer but I use mine a lot everywhere, so with all the files on it, it would take forever and it needs to be more ready to be on the go. I couldn't add the external drive to be excluded under spotlight settings, that also gave and error, but if you use terminal again and navigate to the root of the drive e.g. "cd /Volumes/NameOfExternalDrive" and enter "touch .metadata_never_index" it will create a empty file which tell spotlight not to initiate indexing. Good thing about this is that now if you go to another mac you won't have to try and exclude it in the spotlight settings, this file will tell it to mind it's own business. It can still lock the drive, but now you can at least do something about it like close the finder window.