• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Unmounted disks
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Unmounted disks


  • Subject: Re: Unmounted disks
  • From: Shane Stanley <email@hidden>
  • Date: Tue, 20 Jun 2017 14:26:51 +1000

On 20 Jun 2017, at 12:12 pm, Gil Dawson <email@hidden> wrote:
>
> My script needs to learn the names of unmounted (ejected but still connected)
> hard disks.
>
> Back on 28 April 2014, Yvan Koenig showed us an effective script to parse the
> result from...
>
> do shell script "diskutil list | grep Apple_HFS"
>
> Result:
> "   2:                  Apple_HFS MBProHD                 319.2 GB   disk0s2
>    2:                  Apple_HFS Black iOmega            319.7 GB   disk1s2
>    2:                  Apple_HFS Orange Backup of MBP... 999.9 GB   disk2s2
>    2:                  Apple_HFS Flash Player            20.0 MB    disk3s2"
>
>
> ...which can see both mounted and unmounted disks ("Black iOmega" is
> unmounted).

With APFS around the corner in 1013, that approach is on shaky ground. You'll
probably need to use "diskutil list -plist", and parse the result.

Here's something to get started:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

set theResult to do shell script "diskutil list -plist"
-- make dictionary from property list
set theResult to current application's NSString's stringWithString:theResult
set pListDict to theResult's propertyList()
-- extract relevant info
set disksAndParitions to pListDict's objectForKey:"AllDisksAndPartitions"
set partitionsArray to current application's NSMutableArray's array() -- to
store values
repeat with anEntry in disksAndParitions
        set thePartitions to (anEntry's objectForKey:"Partitions")
        if thePartitions = missing value then -- no partitions means a volume
                (partitionsArray's addObject:anEntry)
        else
                (partitionsArray's addObjectsFromArray:thePartitions)
        end if
end repeat
-- filter by Content type
set thePred to current application's NSPredicate's predicateWithFormat:"Content
== 'Apple_HFS'"
set partitionsArray to partitionsArray's filteredArrayUsingPredicate:thePred
-- get names
return (partitionsArray's valueForKey:"VolumeName") as list

But it looks like 10.13 will require something quite different.

--
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>, <latenightsw.com>


 _______________________________________________
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

  • Follow-Ups:
    • Re: Unmounted disks
      • From: Gil Dawson <email@hidden>
References: 
 >Startup Disk (From: Gil Dawson <email@hidden>)
 >Re: Startup Disk (From: Deivy Petrescu <email@hidden>)
 >Unmounted disks (From: Gil Dawson <email@hidden>)

  • Prev by Date: Unmounted disks
  • Next by Date: Re: Unmounted disks
  • Previous by thread: Unmounted disks
  • Next by thread: Re: Unmounted disks
  • Index(es):
    • Date
    • Thread