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 07, '12 12:18:14PM

And thank you!

For good measure, I'll include the complete version with all the incremental fixes. Thanks again.

------
set alldisks to paragraphs of (do shell script "df -hlg | awk -F/ '/disk*/ {print $5}'")
try
set item 1 of alldisks to ((characters 1 thru -2 of (path to startup disk as string)) as text)
on error
set alldisks to {((characters 1 thru -2 of (path to startup disk as string)) as text)}
end try

set dur to {}
repeat with m in alldisks
considering case
set dur to dur & m
end considering
end repeat

set devnames to paragraphs of (do shell script "df -k | awk -F/ '/disk*/ {print $3}'")
set t to {}
repeat with s in devnames
set t to t & (word 1 of s)
end repeat

set the keylist to dur
set the foundDisks to t
set answer_list to {}

repeat with the_answer in keylist
set theIndex to my CollectUniqueItemIndex(keylist, (the_answer as string))
set theValue to item theIndex of foundDisks
activate
--set answer_list to answer_list & return & ((the_answer & ":" & space & theValue) as string)
--set answer_list to answer_list & ((the_answer & ":" & space & theValue) as string)


set answer_list to answer_list & (the_answer as string)
end repeat

set active_list to {}
repeat with tish from 1 to count of answer_list
--set recordnum to tish

set this_key to item tish of answer_list
set this_value to item tish of foundDisks
--set newrec to {a:1}
set this_rec to {recordnum:tish, diskname:this_key, devname:this_value} as record
set this_rec to {diskname:this_key, devname:this_value} as record

set the end of active_list to this_rec
end repeat

set not_boot_disks to {}
set not_boot_devs to {}
repeat with ant in active_list
if diskname of ant is not in {((characters 1 thru -2 of (path to startup disk as string)) as text)} then
set not_boot_disks to not_boot_disks & (diskname of ant)
set not_boot_devs to not_boot_devs & (devname of ant)
end if
end repeat

try
set your_selected_device_id to choose from list not_boot_disks with prompt "Please choose one or more volumes to be unmounted." with multiple selections allowed
repeat with b in your_selected_device_id
set theIndex to my CollectUniqueItemIndex(not_boot_disks, (b as string))
set theValue to item theIndex of not_boot_devs
try
do shell script "diskutil unmount /dev/" & theValue
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 "Error: " & the error_number & ". " & "The boot volume is the only volume mounted, so it's not possible to unmount anything!" buttons {"OK"} default button 1
end if
end try

on CollectUniqueItemIndex(theList, theItem)
local aListMember
repeat with i from 1 to (count theList)
set aListMember to item i of theList
if aListMember = theItem then
set theIndex to i
exit repeat
end if
end repeat
return theIndex
end CollectUniqueItemIndex
------



[ Reply to This | # ]