Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Script to unmount external drive?

Script to unmount external drive?
Thread Tools
Stingrey
Forum Regular
Join Date: Mar 2003
Location: San Antonio
Status: Offline
Reply With Quote
Feb 10, 2007, 11:27 PM
 
This might be a dumb question, but here goes anyway... I have an external drive with two partitions. One is a clone of my MacBook and the other is free space for temp movies, etc. Both are mounted to my computer as soon as it is brought to life daily after having worked with me @ school each afternoon... The thing is that before I close the laptop down to go back to school with me, I have to highlight my two external disk partitions, drag 'em to the trash, and then they unmount.

I've messed around in Terminal and found that I can mount and unmount my drive"s" with the commands to mount and unmount my drive"s" being as follows:

mount
/usr/sbin/disktool -m /dev/disk1s10
/usr/sbin/disktool -m /dev/disk1s12

unmount
/usr/sbin/disktool -u /Volumes/PacUp
/usr/sbin/disktool -u /Volumes/StingDrive

Out of the two sets of commands, the ones of importance are the ones under the unmount entry. The drives mount automagically when the laptop is cracked open with the drives connected via USB.

I also found that there was an Eject app on the system disk in the extra folder... I am wondering if there is an easy way to create a button similar to that menu bar button which would execute the two commands I noted above in order to be able to quickly eject my disks when necessary, or if there is an even MORE simple way to accomplish what I'm after.

No biggie, just that since I basically need to unmount my disk partitions every day practically before closing my laptop to allow it to sleep, I would like a nifty way to accomplish this. I've used script editor to do a couple of things before, and I can't think of whether or not I've made a file into an executable before, but I suppose I could make a new file that is executable to eject these items and then put a shortcut to it in the Dock, but I'm liking that menubar icon. Regardless of how it is done, where should I look to do what I want to do? I know enough to be dangerous, but not much more!!! :) Any insight appreciated. Worst case scenario, I do perform this drag/eject process at a relatively set time. I might just Cron it to automate it. That might be the easiest way, just that when I'm on the run to school after work or off from work at random vs. heading out early in the a.m. to work before school, it'd be a pain to have it automatically do these things in those circumstances.

Rey :)
     
Chuckit
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Feb 11, 2007, 02:29 AM
 
Open Script Editor. Enter the following:

tell app "Finder"
eject disk "PacUp"
eject disk "StingDrive"
end tell
Then save the script as an application and put it in your dock. Voila.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
Stingrey  (op)
Forum Regular
Join Date: Mar 2003
Location: San Antonio
Status: Offline
Reply With Quote
Feb 11, 2007, 08:06 AM
 
Thanks very much :) I've done that... And I hate to ask for more, but I've had a taste of the good stuff, so to speak. I've used that eject menu item from Apple, and I have used an app called "ejector" as well, that is a menu bar app. Only problem is that Apple's job ejects only disks from the superdrive, and ejector ejects all quickly, but that includes a windows partition that I'd rather not eject... And who knows if I have another disk mounted/inserted at the time, I might not want to eject that at that time.

Any way to make this command a menu bar item and have it look like the Apple version? I played around with that Menu and see there is a unix executable in a folder in that menu item, but replacing that with the eject.app resulting from your insight doesn't do the trick... Basically I'd love to make a button that resides in the menu bar that performs exactly the trick you showed me how to script above as an app. Either way, I've found a solution... Just would like a menu bar version a little more than a dock version, plus I am loving finding out how to mess around with the system a bit more every day!

Rey :)

P.S. FWIW, I've actually considered a new Airport Extreme (have the old version which does the job for me just fine) to alleviate this issue since I believe that the disk would be mounted in a different manner to where I could easily just sleep the book without that "disk removed without being put away properly" type error, but I haven't confirmed whether or not this'd be the case. The TRUE elite solution to this would be to make it where any time I closed the lid on my book it ejected the disks first and THEN went to sleep somehow, but that is probably impossible.
     
WJMoore
Grizzled Veteran
Join Date: Jan 2002
Location: Melbourne, Australia
Status: Offline
Reply With Quote
Feb 11, 2007, 09:14 AM
 
Originally Posted by Stingrey View Post
The TRUE elite solution to this would be to make it where any time I closed the lid on my book it ejected the disks first and THEN went to sleep somehow, but that is probably impossible.
This sounds possible. Apps can be notified when the Mac is going to sleep. It would be relativly simple to write one that ejected certain disks if they were connected when going to sleep. If I find the time this week I might look into writing it if you're interested.
     
Stingrey  (op)
Forum Regular
Join Date: Mar 2003
Location: San Antonio
Status: Offline
Reply With Quote
Feb 11, 2007, 12:14 PM
 
I'm definitely interested :) That would save me from the forgetting to click on the eject icon every now and then... But still I wouldn't mind if that menu bar eject app could somehow be modified to just eject those two disks specifically. Either way, I'm definitely interested!

Rey :)
     
   
Thread Tools
 
Forum Links
Forum 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
Top
Privacy Policy
All times are GMT -4. The time now is 06:28 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,