マウントされたドライブのうちSDカードに相当するものを検出するAppleScriptです。
ただし、iMac Proで採用されたUHS‑II対応のSDカードスロット+UHS-II対応のSDカードがどのように見えるかは実機がないので確認できません。
exFATのことも考えると、「MSDOS format」を抽出条件に入れないほうがいいのかもしれません。
AppleScript名:SDカードを検出 |
— Created 2016-10-04 by Takaaki Naganoya — 2016 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" tell application "Finder" set driveList to every disk whose format is (MSDOS format) and ejectable is true and startup is false repeat with i in driveList set myDisk to disk of (first item of i) set myMountPoint to POSIX path of (myDisk as alias) –> "/Volumes/JVCCAM_SD/" –> "/Volumes/RICOHDCX/" set sdRes to detectSDCard(myMountPoint) of me –> true –SD Card, false –Not SD Card end repeat end tell on detectSDCard(myMountPoint as string) set resData to runCommandString("system_profiler -xml SPStorageDataType") of me set aaDict to (readPlistFromStr(resData) of me) as list set aDictList to (_items of first item of aaDict) repeat with i in aDictList set j to contents of i set aMountPoint to (mount_point of j) as string –> "/Volumes/JVCCAM_SD" –> "/Volumes/RICOHDCX" if aMountPoint is not equal to "/" then if ((aMountPoint & "/") is equal to myMountPoint) then set aDevName to words of (device_name of physical_drive of j) set aMediaName to words of (media_name of physical_drive of j) –SD/SDHC/SDXCのカード検出 set aDevF to ("SD" is in aDevName) or ("SDHC" is in aDevName) or ("SDXC" is in aDevName) set aMediaF to ("SD" is in aMediaName) or ("SDHC" is in aMediaName) or ("SDXC" is in aMediaName) if (aDevF and aMediaF) then return true end if end if end repeat return false end detectSDCard –文字列で与えたシェルコマンドを実行する on runCommandString(commandStr as string) set aPipe to current application’s NSPipe’s pipe() set aTask to current application’s NSTask’s alloc()’s init() aTask’s setLaunchPath:"/bin/sh" aTask’s setArguments:{"-c", current application’s NSString’s stringWithFormat_("%@", commandStr)} aTask’s setStandardOutput:aPipe set aFile to aPipe’s fileHandleForReading() aTask’s |launch|() return current application’s NSString’s alloc()’s initWithData:(aFile’s readDataToEndOfFile()) encoding:(current application’s NSUTF8StringEncoding) end runCommandString –stringのplistを読み込んでRecordに on readPlistFromStr(theString) set aSource to current application’s NSString’s stringWithString:theString set pListData to aSource’s dataUsingEncoding:(current application’s NSUTF8StringEncoding) set aPlist to current application’s NSPropertyListSerialization’s propertyListFromData:pListData mutabilityOption:(current application’s NSPropertyListImmutable) |format|:(current application’s NSPropertyListFormat) errorDescription:(missing value) return aPlist end readPlistFromStr |
More from my site
(Visited 36 times, 1 visits today)