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


Click here to return to the 'Two AppleScripts for unmounting, mounting local disk volumes' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Two AppleScripts for unmounting, mounting local disk volumes
Authored by: llee on May 09, '14 02:16:37PM

Updated for Mavericks:


--begin script


set alldisks to paragraphs of (do shell script ¬
"diskutil list|grep -v 'EFI EFI'|grep -v 'Recovery HD'|grep -o 'disk[0-9][a-z][0-9]*'")
set all_non_boot_disks to paragraphs of (do shell script "df -hlg | awk -F/ '/disk*/ {print $5}'")
set nonbootnumber to (count of alldisks)
if (count of all_non_boot_disks) > 0 then
try
set all_non_boot_disks to items 2 thru nonbootnumber of alldisks
on error
set all_non_boot_disks to {}
end try
activate
repeat with the_Item in alldisks
try
set the_ID to (do shell script "df -hlg | grep -m 1" & space & ¬
quoted form of the_Item & space & "| grep -o 'disk[0-9][a-z][0-9]*'")
do shell script "diskutil unmount" & space & the_ID
on error the error_message number the error_number
if the error_message does not contain ":" then
else
if button returned of (display dialog "A disk couldn't be unmounted.
Would you like to re-mount those already unmounted?" buttons ¬
{"Cancel", "Re-mount"} default button 2) is "Re-mount" then
my mountAll(alldisks)
end if
end if
end try
end repeat
else
my mountAll(alldisks)
end if

on mountAll(alldisks)
set actiondisks to {}
repeat with i in alldisks
if i is not in actiondisks then
set actiondisks to actiondisks & i
end if
end repeat
repeat with myitem in actiondisks
try
do shell script "diskutil mount" & space & myitem
end try
end repeat
end mountAll

--end script



[ Reply to This | # ]