"do shell script" error

Joined
Feb 9, 2006
Messages
3
Reaction score
0
ok, complete beginner here looking for a bit of help.

I have a bash script to unmount one of my volumes without me having to go into Diskutil. It works fine when entering from the command line within terminal, showing results as it goes.

I've attempted to write an applescript to run the terminal and execute the command. After a few seconds it does unmount the volume (without showing results in the terminal) but then Applescript gets an error saying the volume failed to unmount.

Any ideas would be greatly appreciated.

APPLESCRIPT:

tell application "Terminal"
activate

do shell script "disk"

end tell

tell application "Terminal"
quit
end tell



Here is the BASH Script:

#!/bin/bash

##
# Mount/Unmount disks by Volume Name
##

if [ -z "dWerx" ] ; then
echo "usage : disk dWerx"
echo "Mounts dWerx if it's not mounted, and"
echo "unmounts it if it is already mounted."
exit 1
fi

NAME=dWerx
PART=`diskutil list|grep "$NAME"|awk '{print $NF}'`

if [ -z `ls -1 /Volumes/ | grep "$NAME" | awk '{print $NF}'` ] ; 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 $PART
diskutil unmount /Volumes/"$NAME"
fi



Thanks,

Daz
 
Joined
Feb 9, 2006
Messages
3
Reaction score
0
Interesting,

I have now run the script outside of script editor and I do not receive the error message. Something I should have tried before posting! :eek:

However, the terminal does not quit after the drive has unmounted.

daz
 
Joined
Nov 25, 2005
Messages
47
Reaction score
1
You do not need to activate the Terminal to run a shell script. Try just this:

do shell script "disk"
 
Joined
Feb 9, 2006
Messages
3
Reaction score
0
AYE YA YA!!

simplicity.

Thank-you, Thank-you kind sir. I need not gooogle more. For now.

Cheers!

Daz
 
Joined
Nov 28, 2006
Messages
2
Reaction score
0
To mount and unmount in AS Editor, if you have OSX (probably 10.2 or higher), use the standard addition "do shell script" as follows:

do shell script "diskutil mount diskXXX"

or

do shell script "diskutil unmount diskXXX"

To get "XXX" for the drive of interest, assuming it's connected (whether mounted or not) open disk utility.app, highlight the drive of interest, and "get info". There will be an identifier in the form of diskXXX which will be something like disk0s3 -- use that in the "do shell script" above. Be aware that the disk identifier will change if the drive is connected in a different order with respect to other drives on the computer.

The mount routine is relatively quick but the unmount can take upwards of 20 seconds (!) for reasons that I and a number of other folks are trying to figure out -- this is the case even though the same command directly in Terminal gives rapid response.

If the response to "unmount" is disk failed to unmount, there is almost certainly an application on that drive that is open, or something else that is active. Of course, you can never unmount the boot drive.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top