AppleScript名:使用メモリーの状況を取得 |
— Created 2017-12-17 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set mRes to retMemoryUsage() of me –> {usedMem:7891, wiredMem:2220, unusedMem:293} on retMemoryUsage() set memRes to do shell script "top -l 1 | head -10 | grep ’PhysMem’" set aRes to (parseStrFromTo(memRes, " ", "M") of me) set bList to {} repeat with i in aRes set mRes to returnNumberOnly(i) of me set the end of bList to mRes end repeat set usedNum to contents of first item of bList set wiredNum to contents of second item of bList set unusedNum to contents of third item of bList return {usedMem:usedNum as integer, wiredMem:wiredNum as integer, unusedMem:unusedNum as integer} end retMemoryUsage on parseStrFromTo(aParamStr, fromStr, toStr) set theScanner to current application’s NSScanner’s scannerWithString:aParamStr set anArray to current application’s NSMutableArray’s array() repeat until (theScanner’s isAtEnd as boolean) — terminate check, return the result (aDict) to caller set {theResult, theKey} to theScanner’s scanUpToString:fromStr intoString:(reference) — skip over separator theScanner’s scanString:fromStr intoString:(missing value) set {theResult, theValue} to theScanner’s scanUpToString:toStr intoString:(reference) if theValue is missing value then set theValue to "" –>追加 — skip over separator theScanner’s scanString:toStr intoString:(missing value) anArray’s addObject:theValue end repeat return anArray as list end parseStrFromTo on returnNumberOnly(aStr) set anNSString to current application’s NSString’s stringWithString:aStr set anNSString to anNSString’s stringByReplacingOccurrencesOfString:"[^0-9]" withString:"" options:(current application’s NSRegularExpressionSearch) range:{0, anNSString’s |length|()} return anNSString as text end returnNumberOnly |
More from my site
(Visited 32 times, 1 visits today)