Hello,
would it be possible to create a macro which would list the attached USB external drives (or just list the devices) and allow me to select a device and unmount that device. I find that it gets a bit tedious to always have to go back to Disk Utility or Finder and go through the unmounting process.
thanks very much
Hi Ronald
You can find inspiration from this post:
This script should do exactly that (well, it lists not only USB disks):
tell application "Finder" to set diskList to name of every disk whose ejectable is true
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:" with multiple selections allowed
if diskToEject is not false then tell application "Finder" to eject diskToEject
Hold down â to select multiple disks.
â
Here as KM macro:
List and Eject Disks.kmmacros (2.0 KB)
thank you VERY MUCH !
I often get into device ejection problems (probably spotlight searching the disk) and the OS asks if I want to âforce ejectâ at the risk of damaging the external drive or USB key. Would you know if it is OK to force eject, and do I have to repeat the same procedure every time (make drive private in spotlight pref, etc).
I wonder if this risk of damage by force ejection is somewhat of a myth (unless the drive is being actively used by a backup for example)
thanks again very much.
As far as I know force-ejecting will not damage a drive, and the worst thing that will happen is data or file system corruption.
Here are a couple of tips/ideas how to deal with Spotlight in such cases, and how to determine if there are other processes preventing you from unmounting the disk.
I made the script a bit nicer:
- It wonât push the Finder to the foreground.
- The list window has a proper title and text.
Just download it again to get the new version.
BTW: If you choose âUSB Device Key Triggerâ from KMâs trigger selection menu you can assign the Media Eject key as trigger, if you have no other use for it:
thank you.
Ideally, shouldnât the eject command be preceeded by a turn off spotlight command, and then a turn back on?
The cannot eject problem is a real pain and is common.
thanks again
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
Perhaps you can exclude that device from automatic scanning. Youâd have to decide if it was worth it to you, of course.
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
OK, try this:
List and Eject Disks [ver 2.1].kmmacros (2.3 KB)
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
fantastic !! thank you very much !
tiny glitch: at the end, the following box is displayed
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.
thank you for your reply.
I donât have the script addition app in question (24U Appearance OSAX).
Do you suggest I purchase it?
Could it perhaps be Bartender 2 which I purchased a month ago?
I once got an error message containing the word OSAX
------- Console Output -------
Sep 14, 2016, 13:38:16 Bartender 2: SecStatucCodeCreateWithPath() error for file:///Library/PrivilegedHelperTools/com.surteesstudios.Bartender.BartenderInstallHelper: -67068
Sep 14, 2016, 13:38:28 kernel: Sandbox: ditto(1949) System Policy: deny(1) file-write-create /System/Library/ScriptingAdditions/BartenderSystemHelper.osax
Canât suggest to purchase it, because I never heard of that Scripting Addition before
Have you looked into the indicated folder?
~/Library/ScriptingAdditions/
(Your message clearly says that there is something.)
Maybe you have installed a demo version long time ago.
Could it perhaps be Bartender 2 which I purchased a month ago?
I donât think that it is related.
First: I predicted nothing. The message window you have posted before has âpredictedâ it
Second: You are in the wrong folder. You are inâŚ
/Library/ScriptingAdditions/
This is the global Scripting Additions folder, which is not the one you need.
Look again at the message: it tells you the correct folder:
/Users/jlette111/Library/ScriptingAdditions/
This is the Userâs Scripting Additions folder und youâll find the offending â24U Appearance OSAX.osaxâ there.
To open that folderâŚ
- copy the path from here
/Users/jlette111/Library/ScriptingAdditions/
- go to the Finder
- press â§âG
- paste the path into the text field of the sheet
- click OK.
âŚand thenâŚ
what should I do ?
âŚdelete the â24U Appearance OSAX.osaxâ if you donât need it. (Or try to get an update if you want to keep it.)