Subject: | |
From: | |
Reply To: | |
Date: | Fri, 3 Aug 2007 09:27:25 -0400 |
Content-Type: | text/plain |
Parts/Attachments: |
|
|
On Aug 3, 2007, at 9:00 AM, T&B wrote:
> Hi Jeff,
>
>>> 2. How can I unmount the external Backup drive when the script is
>>> done, so it can be safely unpugged (FireWire)?
>
>> /usr/sbin/diskutil eject '/Volumes/The DriveName'
>
> That seems to work great, thanks :-)
>
> Now I just need an answer to:
>
>>> 1. How can I check whether the external volume "Backup" is
>>> mounted, and conditionally execute the script (else mail to say
>>> there was an error). Simply checking whether /Volumes/Backup
>>> exists isn't reliable since there may be a directory created
>>> there (as I've seen created when the script runs with no disk
>>> attached).
Hi tom
are you writing this just in shell or using applescript also?
here is an apple script check.
tell application "Finder"
display dialog ¬
"What volume name?" with icon 1 default answer " "
set UID to (text returned of result)
activate
if exists disk UID then
display dialog UID & " is already mounted " with icon 0
else
display dialog " some unix mount code goes here "
end if
end tell
here is a bash script check; -- i haven't tried this on in a while.
Basically you grep an " ls " for the volume name you want.
#!/bin/bash
if [ -z $1 ] ; then
echo "usage : disk <jdonovan>"
echo "Mounts <jdonovan> if it's not mounted, and"
echo "unmounts it if it is already mounted."
exit 1
fi
NAME=$1
PART=`diskutil list|grep $NAME|awk '{print $6}'`
if [ -z `ls -1 /Volumes/ | grep $NAME` ] ; then
# check that PART appears to be a disk partition
echo Checking $NAME $PART
if [ `file /dev/$PART | awk '{print $2}'` = "block" ] ; then
echo Mounting $NAME $PART
diskutil mount /dev/$PART
else
echo /dev/$PART does not appear to be a disk partition - exiting
exit 1
fi
else
echo unmounting $NAME
diskutil unmount /Volumes/$NAME
fi
|
|
|