It’s the operating system that should take care of Spotlight when unmounting a disk (and usually it does). But, of course, you can add any command to the script. But before doing that I would make sure that everything is OK. I think it’s not normal if you get the “cannot eject problem” very frequently:
Maybe the Spotlight index is corrupted? Maybe the disk is physically damaged? Problem with the disk controller? USB hub problem? Is the file system catalog on the disk corrupted? Maybe it’s not Spotlight, but another process?, etc.
The cannot eject problem is a real pain and is common.
Well, I see that problem rarely, and then in most cases another process was the culprit.
thank you
good point. I think that the problem is the anti virus Bitdefender. Somehow, according to the documentation, the scanning process is linked to spotlight
the problem is that everytime you eject a device, the exclusion configuration is excluded, even if you install another deivce with the same name.
thanks for your answer
Hello Tom,
The macro works very well.
When I run the macro, I have to click inside the dialog box and pick the device i want to eject (99% of the time only one device).
Is there any way to end the macro by putting the cursor inside the box, so that I can use the up down arrows to pick the device to eject and press Enter?
thanks again very much
It will now remember the previously ejected disk and preselect it in the dialog. If it’s the desired disk you can press OK, if not you can navigate with the arrows.
If the previously ejected disk is not available, it will select the first disk in the list.
tell application "Keyboard Maestro Engine" to set diskToEject to getvariable "previousDisk"
tell application "Finder" to set diskList to name of every disk whose ejectable is true
if diskList does not contain diskToEject then set diskToEject to first item of diskList
tell application (path to frontmost application as text) to set diskToEject to choose from list diskList with title "Eject Disk" with prompt "Select disk(s) to eject:" default items diskToEject with multiple selections allowed
if diskToEject is not false then
tell application "Finder" to eject diskToEject
tell application "Keyboard Maestro Engine" to setvariable "previousDisk" to diskToEject
end if
Probably it has nothing to do with the script. Seems that you have installed a Scripting Addition that is not compatible.
If the script runs fine, then set the option of the Execute AppleScript action to “ignore results”. (However you won’t see any error messages then.) Better: Update the incompatible Scripting Addition, or remove it from the path indicated in the message.
The 24U Appearance OSAX was a great scripting addition, but it has not been well supported in the last few years. (I don't like the way v4.x phones-home either.)
Default Folder 5 no longer relies on the Default Folder X Addition.osax.
The SIMBL.osax is not something you should have on your system, unless you know what requires it. It allows code-injection into apps, and theoretically is a serious security threat. I reluctantly stopped using utilities that required it several years ago for that reason and because it made my system a little less stable.
Thank you very much for the script. This is the result. What should I do now? I could delete textexpander which would be a pain because I have a library of snippets. That being said, I trust your advice
INSTALLED OSAX REPORT 2016/10/21 14:07
System Domain Osaxen
/System/Library/ScriptingAdditions/
Digital Hub Scripting.osax
StandardAdditions.osax
Local Domain Osaxen
/Library/ScriptingAdditions/
Adobe Unit Types.osax
Default Folder X Addition.osax
SIMBL.osax
/System/Library/ScriptingAdditions/→ Leave this folder as it is. These Additions are installed by macOS
Digital Hub Scripting.osax
StandardAdditions.osax
/Library/ScriptingAdditions/
Adobe Unit Types.osax → Installed by Adobe products. Check the version of the .osax (Finder Info), it should be 2.1.0. If it’s older thenupdate it.
Default Folder X Addition.osax → See Chris’ (@ccstone) post above.
SIMBL.osax → Ditto.
~/Library/ScriptingAdditions/
TextExpander Addition.osax → Keep it if you’re using the Textexpander app.
I could delete textexpander which would be a pain because I have a library of snippets.
I think nobody has said you should delete Textexpander.