AppleScript名:使用中のMacの製品呼称を取得する v3 |
use AppleScript version "2.5" use scripting additions use framework "Foundation" set mRes to retModelInfo() of me –> "MacBook Pro with Retina display, Intel Core i7, 15\" (Mid 2012)" on retModelInfo() set pListPath to "/System/Library/PrivateFrameworks/ServerInformation.framework/" & "Versions/A/Resources/English.lproj/SIMachineAttributes.plist" set aRec to retDictFromPlist(pListPath) of me set hwName to (do shell script "sysctl -n hw.model") –> "MacBookPro10,1" set aMachineRec to retRecordByLabel(aRec, hwName) set aMachineRec2 to contents of first item of aMachineRec return (marketingModel of _LOCALIZABLE_ of aMachineRec2) end retModelInfo –Read plist as record on retDictFromPlist(aPath) set thePath to current application’s NSString’s stringWithString:aPath set thePath to thePath’s stringByExpandingTildeInPath() set theDict to current application’s NSDictionary’s dictionaryWithContentsOfFile:thePath return theDict as record end retDictFromPlist –リストに入れたレコードを、指定の属性ラベルの値で抽出 on filterRecListByLabel(aRecList as list, aPredicate as string) –ListからNSArrayへの型変換 set aArray to current application’s NSArray’s arrayWithArray:aRecList –抽出 set aPredicate to current application’s NSPredicate’s predicateWithFormat:aPredicate set filteredArray to aArray’s filteredArrayUsingPredicate:aPredicate –NSArrayからListに型変換して返す return filteredArray as list end filterRecListByLabel –指定レコードの指定ラベルの値を取得する on retRecordByLabel(aRec as record, aKey as string) set aDic to current application’s NSDictionary’s dictionaryWithDictionary:aRec set aVal to aDic’s valueForKey:aKey return aVal as list end retRecordByLabel –指定レコードの指定ラベルの値を取得する on retRecordByKeyPath(aRec as record, aKey as string) set aDic to current application’s NSDictionary’s dictionaryWithDictionary:aRec set aVal to aDic’s valueForKeyPath:aKey return aVal end retRecordByKeyPath |
More from my site
(Visited 52 times, 1 visits today)