Re: how to eject a firewire drive natively
Re: how to eject a firewire drive natively
- Subject: Re: how to eject a firewire drive natively
- From: email@hidden
- Date: Sun, 21 Mar 2004 23:39:31 +1100
well i have the solution with hdiutil put in a polished applescript.
for anybody who's interested, i have copied it here:
set script_title to "iPodEjecter"
set ipod_name to "iPod"
on write_to_log(msg)
global script_title
set log_filename to POSIX path of (path to library folder from user
domain) & "Logs/" & script_title & ".log"
set msg to ((current date) as string) & ": " & msg
try
do shell script "echo " & quoted form of msg & " >>" & log_filename
end try
end write_to_log
on check_mount()
global ipod_name
try
set mount_out to (do shell script "mount 2>&1|grep -i " & quoted form
of ipod_name)
on error
error "parse error: probably no " & ipod_name & " connected"
end try
if (length of paragraphs of mount_out) > 1 then
error "parse error: to many output lines from mount-grep pipe"
end if
return mount_out
end check_mount
on eject_tries(devname)
set eject_ok to false
set eject_retry to 1
set eject_out to "empty"
repeat while eject_retry < 10
try
set eject_out to (do shell script "hdiutil eject " & quoted form of
devname & " 2>&1")
set eject_ok to true
exit repeat
on error
set eject_retry to eject_retry + 1
end try
end repeat
if not eject_ok then
error "eject error: given up after " & eject_retry & " times
(output: " & eject_out & ")"
end if
return eject_retry
end eject_tries
try
-- check if ipod exists
check_mount()
delay 3
-- check again if ipod exists (and get the"mount" text)
set mount_out to check_mount()
-- anaylse the mount text for the device_name
try
set store_tid to text item delimiters
set text item delimiters to space
set device_name to first text item of mount_out
set text item delimiters to store_tid
on error
set text item delimiters to store_tid
end try
-- eject tries
set eject_retry to eject_tries(device_name)
write_to_log("success! (after " & eject_retry & " times.)")
on error e
write_to_log(e)
beep
end try
it's kind of slow -- hditutil seems to takes ages when issued via
applescript, but it (mostly) works.
cheers, leo
On 21/03/2004, at 1:33 PM, Graff wrote:
>
I also found out that you can use drutil to open, close, and eject a
>
disk burning drive:
>
do shell script "drutil tray eject"
>
>
This works with drives that can burn CDs or DVDs, I'm not sure if it
>
will work with CD-ROM only drives.
>
>
There is also disktool which can eject a disk provided you have its
>
/dev antry:
>
do shell script "disktool -e disk1s1s2"
>
>
Both of these commands work from AppleScript, although disktool takes
>
a while to do its work.
>
>
Still, I'd love to know why diskutil works on the command line but not
>
from AppleScript.
>
>
-Ken
>
>
On Mar 20, 2004, at 9:15 PM, email@hidden wrote:
>
>
> i did more trials:
>
>
>
> diskutil doesn't work so fare, but hdiutil does!!!
>
>
>
> unfortunatly hdiutil needs the volume as "/dev/"-device, so you have
>
> to find it with mount or so.
>
>
>
> two "do shell script"s... seems pretty messy to me, but its the only
>
> path i can see...
>
>
>
> cheers, leo
>
>
>
>
>
> On 19/03/2004, at 5:59 AM, Graff wrote:
>
>
>
>> I see that no one had any comments on this topic so I thought maybe
>
>> I'd touch on it again in case it was overlooked. Does anyone have
>
>> any idea what is going wrong with this? For some reason I have a
>
>> "do shell script" command that is only half working and I can't see
>
>> any reason why.
>
>>
>
>> -Ken
>
>>
>
>> On Mar 16, 2004, at 12:03 AM, Graff wrote:
>
>>
>
>>> You could always use the command-line tool diskutil:
>
>>> -----------
>
>>> set posixPath to quoted form of ("/Volumes/" & diskName)
>
>>> do shell script "diskutil eject " & posixPath
>
>>> -----------
>
>>>
>
>>> Ok, oddly enough I just tried this and I'm having problems with it.
>
>>> I used this script:
>
>>> -----------
>
>>> set diskName to "Jedi Academy Disc 1"
>
>>> -- Jedi Academy Disc 1 is a CD-ROM disk
>
>>> set posixPath to quoted form of ("/Volumes/" & diskName)
>
>>> do shell script "diskutil eject " & posixPath
>
>>> -----------
>
>>>
>
>>> This ends up producing the command:
>
>>> diskutil eject '/Volumes/Jedi Academy Disc 1'
>
>>>
>
>>> Which produces this result in AppleScript:
>
>>> ""
>
>>>
>
>>> The disk gets removed from the desktop and the entry for it in
>
>>> /Volumes is also removed, however the disk does not get ejected and
>
>>> the /dev entry for the disk is still there.
>
>>>
>
>>> When I do the command directly in the shell the disk is removed
>
>>> from the desktop, from /Volumes, the /dev entry is removed, and the
>
>>> disk gets ejected from the drive. This is the result from the
>
>>> command:
>
>>> Disk /Volumes/Jedi Academy Disc 1 ejected
>
>>>
>
>>> Can anyone shed some light on this? I can't figure out why a shell
>
>>> command executed from AppleScript would do this. I even ran the
>
>>> command in a sh shell session to see if there was some sort of
>
>>> difference there. It ran exactly the same under sh as it did in
>
>>> tcsh.
>
>>>
>
>>> -Ken
>
>>>
>
>>>
>
>>> On Mar 15, 2004, at 7:57 PM, leo wrote:
>
>>>
>
>>>> want to eject a firewrire drive (iPod) in applescript via
>
>>>> applescript.
>
>>>>
>
>>>> however, i don't want to use the finder function "eject" due to
>
>>>> finder's
>
>>>> non-interceptable message dialogs when the firewire drive is in
>
>>>> use.
>
>>>>
>
>>>> any idea how i can eject a drive natively or via another more
>
>>>> controllable
>
>>>> method?
>
_______________________________________________
>
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.
_______________________________________________
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.