why won't force-eject work in a script, but will from command line?
why won't force-eject work in a script, but will from command line?
- Subject: why won't force-eject work in a script, but will from command line?
- From: Charles Arthur <email@hidden>
- Date: Thu, 3 Jul 2003 11:06:23 +0100
I have a portable Firewire disk called "LaCie" which, for inexplicable
reasons, won't let itself be ejected from the Finder at the end of the day
when I want to take it home. I get the message "The disk is in use".
However, nothing that I can find is using it - digging around the terminal
(with "lsof") suggests it's just being, I don't know, monitored. No apps
have it.
So I wrote a script to force-eject it using hdiutil. But that doesn't seem
to work - even though when I run the same commands as it seems to be
generating in the script on the command line, everything goes fine.
On the command line, the command is
hdiutil eject -force disk1
which gets the result (last night, for example) of
hdiutil: detach: "disk1" detached successfully.
and the disk icon goes from the Finder. But this script (which I
tried before that) won't do it. Why not? OSX 10.2.6, AS 1.9.1. I'm an
admin on my system, if that makes any difference.
try
set whichfiles to do shell script "lsof | grep \"LaCie\""
set thecount to count paragraphs of whichfiles
display dialog "Apparently " & thecount & " open files on LaCie.
Continue?"
set firstline to paragraph 1 of whichfiles
set diskname to (characters -6 thru -2 of firstline) as string
--was characters -10 thru -2 but this gave "-force dev/disk1" which
failed
--shd be "-force disk1"
set thecommand to ("hdiutil eject -force " & diskname) as string
--display dialog thecommand
--debugging to make sure the correct command is being passed
set thedecision to (display dialog "Force-eject?" buttons {"OK",
"Cancel"})
if thedecision is "OK" then
set theresult to do shell script thecommand
display dialog theresult
end if
on error errnum
display dialog "Errored out - " & errnum
end try
Charles
--
----------------------------
http://www.ukclimbing.com : 1100+ British crags, 350+ British climbing
walls - searchable by distance and anything else you care to think of -
with weather forecasts for every one, plus maps, articles, news and
features. And there's even a cool shop attached.
________________________________________________________________________
This email has been scanned for all viruses by the MessageLabs Email
Security System. For more information on a proactive email security
service working around the clock, around the globe, visit
http://www.messagelabs.com
________________________________________________________________________
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.