AppleScript名:system_profilerの結果のstringのplistをdictionaryにのコピー2 |
— Created 2015-11-01 by Takaaki Naganoya — 2015 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set aTargKey to "machine_name" set aTargGenre to "SPHardwareDataType" set macRes to getSystemProfileInAGenre(aTargGenre, aTargKey) of me –> "MacBook Pro" on getSystemProfileInAGenre(aTargGenre, aTargKey) set sRes to do shell script ("/usr/sbin/system_profiler -xml " & aTargGenre) set aSource to (my readPlistFromStr:sRes) as list set aaList to contents of first item of aSource set aList to _items of aaList repeat with i in aList set aDict to (current application’s NSMutableDictionary’s dictionaryWithDictionary:(contents of i)) set aKeyList to (aDict’s allKeys()) as list if aTargKey is in aKeyList then set aRes to (aDict’s valueForKeyPath:aTargKey) if aRes is not equal to missing value then return aRes as string end if end if end repeat return false end getSystemProfileInAGenre –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)