Re: Considerable simplification should be possible
Re: Considerable simplification should be possible
- Subject: Re: Considerable simplification should be possible
- From: Nigel Garvey <email@hidden>
- Date: Mon, 28 Apr 2014 09:55:39 +0100
"koenig.yvan" wrote on Mon, 28 Apr 2014 09:54:23 +0200:
>
>Le 28/04/2014 à 07:54, Lists <email@hidden> a écrit :
>
>> set theVolumeNamesList to {}
>> set HFSdiskList to do shell script "diskutil list | grep Apple_HFS"
>> set x to paragraphs of HFSdiskList
>> repeat with LVar in items of x
>> set thisVolumeName to word 3 of LVar
>> set the end of theVolumeNamesList to thisVolumeName
>> end repeat
>the list stored in the variable x resemble to that :
>{" 2: Apple_HFS Macintosh HD 999.3 GB
>disk0s2", " 2: Apple_HFS Samsung 32
31.1 GB
> disk1s2"}
>(1) as you may see, word 3 is not really the name of the volumes
>Here is the edited beginning of the script
>
>set theVolumeNamesList to {}
>set theVolumeIDsList to {}
>set HFSdiskList to do shell script "diskutil list | grep Apple_HFS"
>set x to paragraphs of HFSdiskList
>repeat with LVar in x
> set nameWords to words 3 thru -4 of LVar
> set thisVolumeName to text (offset of (item 1 of nameWords) in LVar)
thru
>((offset of (item -1 of nameWords) in LVar) - 1) of LVar & item -1 of
>nameWords
> set end of theVolumeNamesList to thisVolumeName
> set end of theVolumeIDsList to word -1 of LVar
>end repeat
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;}'")
NG
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden