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


Click here to return to the 'Mount and unmount external drives easily via AppleScript ' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Mount and unmount external drives easily via AppleScript
Authored by: llee on Apr 26, '12 07:07:02PM

This time for sure!

------
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 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 alldisks
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 & (the_answer as string)
end repeat

set actiondisks to {}
repeat with each_device_id in answer_list
if each_device_id is not in {((characters 1 thru -2 of (path to startup disk as string)) as text), "MobileBackups"} then --then
set theIndex to my CollectUniqueItemIndex(answer_list, (each_device_id as string))
set theValue to item theIndex of foundDisks
set actiondisks to actiondisks & theValue
end if
end repeat

if (count of actiondisks) > 0 then
repeat with myitem in actiondisks
try
do shell script "diskutil unmount /dev/" & myitem
end try
end repeat
else
set dur to paragraphs of (do shell script
"diskutil list -plist|grep -A 1 VolumeName|grep -o '<string>'.*'</string>'|grep -o [^'<'string'>'].*[^'<''/'string'>']")
set foundDisks to {}
repeat with i in dur
if i is not in {((characters 1 thru -2 of (path to startup disk as string)) as text), "MobileBackups"} then
set deviceLine to (do shell script "diskutil list | grep \"" & i & "\" | awk '{ print $NF }'")
set actiondisks to actiondisks & (paragraphs of deviceLine)
else
--set namecount to namecount - 1
end if
end repeat
repeat with myitem in actiondisks
try
do shell script "diskutil mountDisk /dev/" & myitem
end try
end repeat
end if

on CollectUniqueItemIndex(theList, theItem) -- the Item can be string, number, constant, app object or list
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 | # ]
Mount and unmount external drives easily via AppleScript
Authored by: tingo on Feb 19, '12 03:32:56AM

The original script by Swordfish doesn't work for me (10.6.8). nickv2002's version does work, but only for the couple of USB devices I've tested it with. My main Firewire device gives a "cannot be found" message. I wonder if that's because there's a non-English character () in its name. Any idea? I have not a clue how Apple script works...



[ Reply to This | # ]