Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Applescript to Mount/Unmount A Disk...

Hi all

Maybe someone can help me with this... I'm trying to create a set of scripts to use with Chronosync to mount and unmount my external firewire drive before and after a sync operation...

I had gotten this to work in the past by searching for the drive's name (since its mount point can change, as I recall) but I seem to have misplaced this code...

I also need a delay in the mount script until it is actually mounted so Chronosync doesn't bomb out...

Thanks!

Mac Pro 2.66, 1.0 GB RAM, 23 Apple Cinema HD Display, Mac OS X (10.4.7), EyeTV 200, Powerbook G4/667, 512 MB RAM

Posted on Nov 2, 2006 4:46 PM

Reply
Question marked as Best reply

Posted on Nov 2, 2006 6:19 PM

--Assuming the name you have given to the drive is "External FW" try this:

set driveName to "External FW"
set driveInfo to do shell script "diskutil list | grep \"" & driveName & "\""
set driveID to last word of driveInfo
--In the following:
--TO MOUNT (use mount to mount just the single volume, if the disk is partitioned, or use mountDisk to mount all volumes on the disk)
--To UNMOUNT (use unmount for just the single volume, or use unmountDisk for all volumes)
--For example:
do shell script "diskutil mount " & driveID & ""
--do shell script "diskutil unmount " & driveID & ""

--I'm assuming you can work this into any remaining
--script you need. The "unmount" can be pretty slow.
--An alternative is:


tell application "Finder"
eject driveName
end tell

--but there's no Finder equivalent for "mount"
23 replies
Question marked as Best reply

Nov 2, 2006 6:19 PM in response to Justin Surpless

--Assuming the name you have given to the drive is "External FW" try this:

set driveName to "External FW"
set driveInfo to do shell script "diskutil list | grep \"" & driveName & "\""
set driveID to last word of driveInfo
--In the following:
--TO MOUNT (use mount to mount just the single volume, if the disk is partitioned, or use mountDisk to mount all volumes on the disk)
--To UNMOUNT (use unmount for just the single volume, or use unmountDisk for all volumes)
--For example:
do shell script "diskutil mount " & driveID & ""
--do shell script "diskutil unmount " & driveID & ""

--I'm assuming you can work this into any remaining
--script you need. The "unmount" can be pretty slow.
--An alternative is:


tell application "Finder"
eject driveName
end tell

--but there's no Finder equivalent for "mount"

Nov 2, 2006 8:39 PM in response to Justin Surpless

I've tried this with a volume on an internal (SATA) drive that's not in use.

As you say, mounting is no problem.

At the moment, I'm not having any luck "ejecting" the volume by the Finder approach. Actually, if you look at Disk Utility.app, "eject" isn't an option for internal disks, whereas it is for external disks.

Using the "diskutil unmount" approach, the volume does unmount, but on my machine it's taking nearly 20 seconds to do so -- which is what I meant by slow! If you do this directly with Disk Utility.app, the unmount is very quick. The unmount is also very quick if done directly in the Terminal. At the moment I don't see what accounts for the difference but obviously it has something to do with the "do shell script" command.

I'm interested in what you find upon further experimentation.

Nov 3, 2006 1:55 AM in response to osimp

That's pretty much what I've found... I discovered I was able to use the unmount command...

I think what you're saying about not being able to eject an internal disk is correct...

To me, the delay isn't a huge issue since it's not that bad and in addition, it'll be happening when I'm not there typically so even more so...

If I figure something out to improve the speed, I'll let you know...

Thanks again

Nov 4, 2006 2:37 PM in response to osimp

I'm using two different copies of the script... aside from the drive name they are identical... they look like this...

set driveName to "Media Backup"
set driveInfo to do shell script "diskutil list | grep \"" & driveName & "\""
set driveID to last word of driveInfo

do shell script "diskutil mount " & driveID & ""

delay 5

----

it doesn't seem to ask for the password if I mount it twice in quick succession... this is for the internal SATA drive, BTW... not sure if it matters but it's also a partition...

Nov 4, 2006 4:09 PM in response to Justin Surpless

I've played with a pasted version of your posted script and can't make it misbehave (I named an internal SATA partition appropriately) -- UNLESS I set Permissions for that partition to "no access" (then the partition essentially disappears, showing up in Disk Utility, but never on the desktop -- however, I'm never asked for a password).

So: How are you logged in?
What does Get Info show for that partition, including "Details"

Nov 4, 2006 5:04 PM in response to Justin Surpless

Basically, I'm working with the same setup.

If the issue occurred only with unmount, I'd suspect something on the volume inhibiting the unmount -- but that doesn't make any sense for mounting an unmounted volume.

Nevertheless, if you happen to have a partition which could be erased, it might be interesting if that blank partition also creates the issue (I've been testing this with a blank partition).

In the meantime, I'll certainly keep thinking about this.

Applescript to Mount/Unmount A Disk...

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.