ソフトウェア的にアンマウントした状態で、各種接続端子(USBとか)で物理的につながったままの外部ドライブの名称を取得するAppleScriptです。
いちど、そういう質問が来て「できるわけがない」という回答をしていました。AppleScriptの性質上、ソフトウェア的にそういう操作は許可されていません。そもそも、そんな機能はありません。
ただ、まさかshell command経由でそうした操作ができるとは知りませんでした。冗談半分で調べてみたら存在したという状況です。
AppleScript名:ソフトウェア的にアンマウントしたが物理的に接続解除していないHard Driveの名前を取得する v2 |
— Created 2017-06-20 Shane Stanley — Modified 2017-06-20 Takaaki Naganoya 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() –> (NSDictionary) {AllDisks:{"disk0", "disk0s1", "disk0s2", "disk0s3", "disk1"}, AllDisksAndPartitions:{{DeviceIdentifier:"disk0", Size:500277790720, Content:"GUID_partition_scheme", Partitions:{{DiskUUID:"FC89778D-9028-4FAA-8118-F74802B0664E", DeviceIdentifier:"disk0s1", Size:209715200, Content:"EFI", VolumeName:"EFI", VolumeUUID:"85D67001-D93E-3687-A1C2-79D677F0C2E0"}, {DiskUUID:"AAF54C8C-9229-4DC1-8EA5-5FCCE9050DC4", DeviceIdentifier:"disk0s2", Size:499418034176, Content:"Apple_CoreStorage"}, {DiskUUID:"EE72FC16-C614-4C77-9048-6EF118451D48", DeviceIdentifier:"disk0s3", Size:650002432, Content:"Apple_Boot", VolumeName:"Recovery HD", VolumeUUID:"3400E36B-24AA-3B7A-93E3-BBDCDFF48548"}}}, {DeviceIdentifier:"disk1", Size:499055067136, MountPoint:"/", Content:"Apple_HFS", VolumeName:"Cherry"}}, WholeDisks:{"disk0", "disk1"}, VolumesFromDisks:{"Cherry"}} — extract relevant info set disksAndParitions to pListDict’s objectForKey:"AllDisksAndPartitions" –> (NSArray) {{DeviceIdentifier:"disk0", Size:500277790720, Content:"GUID_partition_scheme", Partitions:{{DiskUUID:"FC89778D-9028-4FAA-8118-F74802B0664E", DeviceIdentifier:"disk0s1", Size:209715200, Content:"EFI", VolumeName:"EFI", VolumeUUID:"85D67001-D93E-3687-A1C2-79D677F0C2E0"}, {DiskUUID:"AAF54C8C-9229-4DC1-8EA5-5FCCE9050DC4", DeviceIdentifier:"disk0s2", Size:499418034176, Content:"Apple_CoreStorage"}, {DiskUUID:"EE72FC16-C614-4C77-9048-6EF118451D48", DeviceIdentifier:"disk0s3", Size:650002432, Content:"Apple_Boot", VolumeName:"Recovery HD", VolumeUUID:"3400E36B-24AA-3B7A-93E3-BBDCDFF48548"}}}, {DeviceIdentifier:"disk1", Size:499055067136, MountPoint:"/", Content:"Apple_HFS", VolumeName:"Cherry"}} 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’ OR Content == ’Apple_APFS’ " set partitionsArray to partitionsArray’s filteredArrayUsingPredicate:thePred — get names return (partitionsArray’s valueForKey:"VolumeName") as list |
More from my site
(Visited 33 times, 1 visits today)