Maverick - Eject mounted disk

Hello,

The following script used to work without any problem. Since I’ve upgraded to Maverick this is no longer the case. I get the following error messages:

When executing the “Do shell…” command, I sometime get the following error "error “Finder got an error: Error -69888: Couldn’t unmount disk” number 1

I also get the following message when trying to eject the disk.
AppleScript Error Finder got an error: Can’t get disk “NX5U”.

Would anyone have an idea what coud be the problem?

Thanks!

tell application "Finder"
	do shell script "diskutil eraseVolume \"MS-DOS FAT32\" NX5U /Volumes/NX5U"
	eject disk "NX5U"
end tell

Hi DPaquin,

I don’t know much about disks, but things have been changing a lot in the upgrades from what I see. You might need to look if there are changes in the man page for the diskutil.

Anyway, in Finder try running:

tell application "Finder"
	first disk whose name is "NX5U"
end tell

It still works when working with a test disk image for me. Just verifying that the disk image ejects with the ‘eject’ command.

gl,
kel

Another way you can try to verify if the eject command works:

tell application "Finder"
	exists disk "Macintosh HD"
end tell

Here’s another one:

tell application "System Events"
	ejectable of disk "Macintosh HD"
end tell

Hi,

the Finder is not needed at all to run shell scripts. Try


do shell script "diskutil eraseVolume \"MS-DOS FAT32\" NX5U /Volumes/NX5U"
tell application "Finder" to eject disk "NX5U"

Sometimes when I don’t want to fool around:

tell application "System Events"
	properties of disk "Macintosh HD"
end tell

:smiley:

Thanks everybody for your help!

I’ve used the following and everything works fine. 18 of 20 cards were successfully formatted and ejected. However, I had to add a 3 seconds delay for the system to see the NX5U card. Without the delay, the system tried to eject an unmounted card.


Do shell script "diskutil eraseVolume \"MS-DOS FAT32\" NX5U /Volumes/NX5U"
delay 3
tell application "Finder" to eject disk "NX5U"

You can do this in a single do shell script:

do shell script "diskutil eraseVolume \"MS-DOS FAT32\" NX5U /Volumes/NX5U && diskutil unmount /Volumes/NX5U"

When the erase volume fails the disk won’t be unmounted. If the disk always needs to be unmounted you can change the ‘&&’ for ‘;’ in the command.