Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'AppleScript for unmounting volumes (without do shell script)' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
AppleScript for unmounting volumes (without do shell script)
Authored by: DougKorns on May 22, '12 06:07:26AM

Every time I see scripts with some cryptic UNIX command in them, I get the impression that the UNIX people just don't get AppleScript. The full capability to do this action can be done simply and elegantly using just Finder Scripting:

--
tell application "Finder"
set StartupDisk to name of first disk whose startup is true
set EveryDisk to name of every disk
--set LocalDisks to name of every disk whose local volume is true
--set ServerDisks to name of every disk whose local volume is false

set EligibleDisks to {}
repeat with EachDisk in EveryDisk
if EachDisk is not in {StartupDisk, "home", "net"} then
set end of EligibleDisks to EachDisk -- Eligible for dismount
--Might also want to omit "Time Machine Backups"
end repeat

choose from list EligibleDisks with prompt "Please choose one or more volumes to be unmounted." default items EligibleDisks with multiple selections allowed
set ChosenDisks to the result

if class of ChosenDisks is boolean then
-- User Canceled
else
repeat with EachDisk in ChosenDisks
try
tell application "Finder" to eject EachDisk
on error ErrMsg number ErrNmbr
display dialog "Unable to eject disk: " & EachDisk
end try
end repeat
end if
end tell
--
Here the default list to dismount is preset to all eligible disks.

The problem with two disks having the same same can't be solved, without additional script to recognize that situation, because you can't identify which disk of the two was selected in the 'choose from list' result.



[ Reply to This | # ]
AppleScript for unmounting volumes (without do shell script)
Authored by: llee on Jun 11, '12 01:29:29PM

When you're dealing with more than one disk with the same name, i think there's a good chance you'll remember which was mounted in which order. If you can't, you're going to have to examine anyway, in which case it's probably useless to depend on this kind of script to give you enough information to be of any benefit.



[ Reply to This | # ]