Mac Help Forums


Reply
Thread Tools Display Modes

"do shell script" error

 
New Member
Join Date: Feb 2006
Location: SF, Ca.
Posts: 3
 
      9th February 2006
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
 
Reply With Quote
 
 
 
 
New Member
Join Date: Feb 2006
Location: SF, Ca.
Posts: 3
 
      9th February 2006
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!

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

daz
 
Reply With Quote
 
Member
Join Date: Nov 2005
Posts: 47
 
      9th February 2006
You do not need to activate the Terminal to run a shell script. Try just this:

do shell script "disk"
 
Reply With Quote
 
New Member
Join Date: Feb 2006
Location: SF, Ca.
Posts: 3
 
      9th February 2006
AYE YA YA!!

simplicity.

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

Cheers!

Daz
 
Reply With Quote
 
New Member
Join Date: Nov 2006
Posts: 2
 
      28th November 2006
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
do shell script "diskutil unmount diskXXX" osimp AppleScript 0 28th November 2006 12:44 AM
MAC SE: "Bomb" crash "System Error" - "Address Error" help! Stephen E Buggie Misc 0 15th February 2006 09:17 PM
relative path in "do shell script" xkp AppleScript 2 7th April 2004 06:31 PM
do shell script "system_profiler... Bruno AppleScript 3 28th January 2004 05:16 AM
Source code for "syslog()" and "open" command shell Alain Birtz Programmer Help 3 2nd January 2004 03:03 AM


All times are GMT +1. The time now is 08:07 PM.
Mac-Help.com is an independent website and is not affiliated with Apple Inc.


Welcome!
Welcome to the Mac Help Forums
 


Latest Threads
Unable to log in to websites
AMonty20 (2 Hours Ago, 05:52 PM)

Add Different Speech Commands
bae_22 (3 Hours Ago, 04:40 PM)

Login (2 macs) passwords spontaniously changed?
Roger Vaught (4 Hours Ago, 03:31 PM)

Best car charger or inverter for Macbook Pro?
imeme87 (4 Hours Ago, 03:22 PM)

New book about Steve Jobs << take part in it!
Arjan (10 Hours Ago, 09:37 AM)

 


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51