i have a nagging problem with an application i’m working on…
a curtain part of the app has the very simple function of ejecting volumes dropped on a button (using tell “finder” to eject…).
it was working fine for some time (or so i seem to recall), and then a weird problem started:
when i drag a volume to the button, i get a massage from the finder that the disk is in use and cannot be ejected, and then i cannot eject the disk in any other way (except by force), until i quit my app. i’ve tried using “do shell script udiutil -eject” and “udiutil unmount” instead of telling “finder” to eject, to the same result. (different error massages obviously).
i can’t figure out what exactly goes wrong there, but my guess is that once a volume is dropped on the button (using “on drop” handler), it is perceived to be used by the application, and won’t be released from it, until it quits.
actually, i have been using the ignoring statement, as without it the entire program would hang on the drop for quite some time…
however, the problem with disks staying “in use” by the program remains regardless to the existence of such a handler.
maybe something needs to happen in the “conclude drop” handler…? meh… i don’t know…just a guess.
It shouldn’t hang on the drop. Maybe you should fix that first. The big ignoring staement might be the reason why the volume is still in use. My test app was hanging also when I tried to eject the disk. I had to force quit the app. Then the disk ejected. Then I used the ignoring stement and it ejected alright.
o.k. here it is, (the part of it which deals with volumes, that is…)
on drop theObject drag info dragInfo
if name of theObject is "tbutton" then
if "file names" is in types of pasteboard of dragInfo then
set droppeditems to {}
set preferred type of pasteboard of dragInfo to "file names"
set droppeditems to (contents of pasteboard of dragInfo)
set thefiles to {}
set thedisks to {}
repeat with anitem in droppeditems
set anitem to ((anitem as POSIX file) as alias)
if kind of (info for anitem) is "Volume" then
set thedisks to thedisks & anitem
else
set thefiles to thefiles & anitem
end if
end repeat
if thedisks is not {} then
(*try
do shell script "hdiutil eject " & (quoted form of anitem) -- i've tried this piece of code (without converting the posix path to alias)
on error errtext
display dialog (errtext as string) buttons {"OK"} default button 1 -- as an alternetive to the finder's eject => same result.
end try*)
ignoring application responses -- without this the app hangs for a long time.
tell application "Finder"
try
eject thedisks
on error errtext
display dialog (errtext as string) buttons {"OK"} default button 1 -- here's where i get the massage about the disk being in use.
end try
end tell
end ignoring
end if
return true
else
return false
end if
end if
end drop
if you log the result of thiis line, do you get an alias reference to a disk?
set anitem to ((anitem as POSIX file) as alias)
log anitem
What I did was get the name of the disk and use disk disk_name.
Also, I don’t think you should put display dialog in the Finder tell block and ignore application responses. You might try just placing the ignoring statement around the eject disk part.