(1) as you may see, word 3 is not really the name of the volumes
we may get the true names from words 3 thru -4 of LVar
CAUTION, the words separators aren't necessarily spaces. A comma for instance is a word separator.
This is why in the script belowI just use the offsets of firt and last word of the volume names to rebuild them.
On 28 Apr 2014, at 6:55 pm, Nigel Garvey <
email@hidden> wrote:
Or the same can be achieved with:
set theVolumeNamesList to paragraphs of (do shell script "diskutil list | sed -En '/[^[:alpha:]]+Apple_HFS / {s///;s/[[:blank:]]{2}.+$//p;}'")
Yes, but he's after both volume names and device identifiers.
set namesArray to {}
set idArray to {}
set theText to do shell script "diskutil list -plist"
tell application "System Events"
set diskInfo to AllDisksAndPartitions of (get value of (make property list item with properties {text:theText}))
end tell
repeat with aDisk in diskInfo
repeat with aPartition in Partitions of aDisk
if |Content| of aPartition is "Apple_HFS" then
set end of namesArray to VolumeName of aPartition
set end of idArray to DeviceIdentifier of aPartition
end if
end repeat
end repeat
Or the same approach in ASObjC:
use framework "Foundation"
on getNamesAndIDs()
set namesArray to {}
set idArray to {}
set theText to do shell script "diskutil list -plist"
set aString to current application's NSString's stringWithString:theText
set diskInfo to (aString's propertyList()'s valueForKeyPath:"AllDisksAndPartitions") as list
repeat with aDisk in diskInfo
repeat with aPartition in Partitions of aDisk
if |Content| of aPartition is "Apple_HFS" then
set end of namesArray to VolumeName of aPartition
set end of idArray to DeviceIdentifier of aPartition
end if
end repeat
end repeat
return {namesArray, idArray}
end getNamesAndIDs