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


Click here to return to the 'This script is flawed!' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
This script is flawed!
Authored by: llee on May 09, '12 08:22:33PM

Hmm, well, could it be as short and sweet as this?

-----
set alldisks to paragraphs of (do shell script "df -hlg | awk -F/ '/disk*/ {print $5}'")
set nonbootnumber to (count of alldisks)
try
set alldisks to items 2 thru nonbootnumber of alldisks
activate
set your_selected_device_id to choose from list alldisks with prompt "Please choose one or more volumes to be unmounted." with multiple selections allowed
repeat with the_Item in your_selected_device_id
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
-----

Edited on May 09, '12 08:55:12PM by llee



[ Reply to This | # ]
I like it (shorter and simpler)
Authored by: vczilla on May 10, '12 09:32:23AM

I tried your shorter version and indeed it works here too. I think the key to this story was to have just one list, the one generated by 'df -l'.

Since you asked me (and I know that doesn't really matter anymore),
here is the output of 'df -k | awk -F/ '/disk*/ {print $3}' on my machine:

% df -hlg | awk -F/ '/disk*/ {print $5}'

LionHD
Spare
MacExt
SmallSave

and 'df -k | awk -F/ '/disk*/ {print $3}':

 df -k | awk -F/ '/disk*/ {print $3}'
disk0s2                   79203656  51490116  27457540    66%    
disk2s2                  365784156 332114676  33669480    91%    
disk1s1                   66559996  65618364    941632    99%    
disk1s2                   36141052  35825216    315836   100%    
disk1s3                   53588152  48312940   5275212    91%    
disk3s1                  256702603 251655316   5047286    99%    
disk3s2                  306239060 303196908   3042152   100%    
disk3s3                   35929372  34222232   1707140    96%   

That's why it didn't work here.

As a side note, there's a slight typo in the awk script regex, which should be /disk.*/ and not /disk*/ (luckily it doesn't change anything for the intended purpose).

I'm glad you didn't take it the wrong way and that you came up with a really short solution, and I hope I didn't came off as being too pedantic. ;-)



[ Reply to This | # ]