AppleScript名:Macの製品カテゴリ名を取得する |
— Created 2015-11-01 by Takaaki Naganoya — 2015 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set macRes to getSystemProfileInAGenre("SPHardwareDataType", "machine_name") of me –> "MacBook Pro" on getSystemProfileInAGenre(aTargGenre as string, aTargKey as string) set sRes to do shell script ("/usr/sbin/system_profiler -xml " & aTargGenre) set aSource to (readPlistFromStr(sRes) of me) 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 28 times, 1 visits today)