AppleScript名:光学ドライブ情報の取得.scptd |
— – Created by: Takaaki Naganoya – Created on: 2018/03/10 — – Copyright © 2018 Piyomaru Software, All Rights Reserved — use AppleScript version "2.5" — El Capitan (10.11) or later use framework "Foundation" use scripting additions set dInfoList to getOpticalDrivesInfo() of me –> {{driveNum:"1", vendorName:"BUFFALO", productName:"Optical Drive", supportLevel:"Unsupported", revisionNo:"BFT6", busName:"USB", suppoortLevel:"Unsupported"}, {driveNum:"2", vendorName:"MATSHITA", productName:"BD-MLT UJ240AS", supportLevel:"Unsupported", revisionNo:"1.00", busName:"USB", suppoortLevel:"Unsupported"}} –光学ドライブの情報を返す on getOpticalDrivesInfo() set dList to paragraphs of (do shell script "drutil list") set d2List to removeItemFromList(dList, "") of me if length of d2List = 1 then return false –No Optical Drive set d2List to rest of d2List –skip first header row set dMainList to {} repeat with i in d2List set tmpA to (current application’s NSString’s stringWithString:i) set tmpB to (tmpA’s componentsSeparatedByString:" ") as list –parse string by space character set tmpC to removeItemFromList(tmpB, "") of me –remove empty item from list set dNum to first item of tmpC set aVendor to second item of tmpC set supLevel to last item of tmpC set busStr to item -2 of tmpC set revStr to item -3 of tmpC –Product Nameのlist itemをスペースでつないで文字列化 set prodName1 to items 3 thru -4 of tmpC set prodName2 to retStrFromArrayWithDelimiter(prodName1, " ") of me set the end of dMainList to {driveNum:dNum, vendorName:aVendor, productName:prodName2, supportLevel:supLevel, revisionNo:revStr, busName:busStr, suppoortLevel:supLevel} end repeat return dMainList end getOpticalDrivesInfo –1D Listから指定内容の要素をすべて削除する on removeItemFromList(aTargList, aTargValue) set anArray to current application’s NSMutableArray’s arrayWithArray:aTargList repeat set aInd to anArray’s indexOfObject:aTargValue –macOS 10.12〜10.13.0までのNSNotFoundの値定義の間違いというAppleの恥ずかしいバグに対処 if aInd = current application’s NSNotFound or (aInd as real > 9.99999999E+8) then exit repeat anArray’s removeObjectAtIndex:aInd end repeat return anArray as list end removeItemFromList –リストを指定デリミタをはさんでテキスト化 on retStrFromArrayWithDelimiter(aList, aDelim) set anArray to current application’s NSArray’s arrayWithArray:aList set aRes to anArray’s componentsJoinedByString:aDelim return aRes as text end retStrFromArrayWithDelimiter |
More from my site
(Visited 29 times, 1 visits today)