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


Click here to return to the 'AppleScript for selecting local volumes to unmount' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
AppleScript for selecting local volumes to unmount
Authored by: llee on May 10, '12 10:32:19AM

And here's the condensed version:

-----

set alldisks to paragraphs of (do shell script "df -hlg | awk -F/ '/disk*/ {print $5}'")
set nonbootnumber to (count of alldisks)

try
set all_non_boot_disks to items 2 thru nonbootnumber of alldisks
on error
set all_non_boot_disks to {}
end try
if (count of all_non_boot_disks) > 0 then
try
activate
repeat with the_Item in all_non_boot_disks
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]*'")
try
do shell script "diskutil unmount /dev/" & the_ID
on error the error_message number the error_number
display dialog "Error: " & the error_number & ". " & the error_message buttons {"OK"} default button 1
end try
end repeat
on error the error_message number the error_number
if the error_number is -128 or the error_number is -1708 then
else
display dialog "There are no unmountable volumes." buttons {"OK"} default button 1
end if
end try
else
set actiondisks to {}
set allvols to paragraphs of (do shell script "diskutil list -plist | grep -o 'disk[0-9][a-z][0-9]*'")
repeat with i in allvols
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 mountDisk /dev/" & myitem
end try
end repeat
end if
-----



[ Reply to This | # ]