-
Open Terminal
-
Run
crontab -e
-
Add this line-
0 * * * * osascript <FULL_PATH_TO_SCRIPT>/RAM_Overuse_Notification.applescript
- save and exit
-- Split string by delimiter | |
on splitText(theText, theDelimiter) | |
set AppleScript's text item delimiters to theDelimiter | |
set theTextItems to every text item of theText | |
set AppleScript's text item delimiters to "" | |
return theTextItems | |
end splitText | |
-- Get current memory stats | |
set vmstat to do shell script "vm_stat" | |
set splitStat to splitText(vmstat, ".") | |
-- list of memory features to check if not zero | |
set memList to {"Compressions", "Decompressions", "Swapins", "Swapouts"} | |
set notif to "" | |
repeat with a from 1 to length of splitStat | |
set theCurrentListItem to item a of splitStat | |
considering case | |
repeat with b from 1 to length of memList | |
set memItemname to item b of memList | |
-- Check each memory feature with the list of features provided above | |
if theCurrentListItem contains memItemname then | |
-- Get count of the feature | |
set compressionsList to splitText(theCurrentListItem, ":") | |
set compressionsNum to item 2 of compressionsList | |
set compressionsNum to splitText(compressionsNum, space) | |
set compressionsNum to compressionsNum's last item | |
-- check if the count is not equal to zero | |
if compressionsNum is not equal to "0" then | |
set notif to notif & " | |
" & memItemname & " " & compressionsNum | |
end if | |
end if | |
end repeat | |
end considering | |
end repeat | |
-- Show notification if count of anything is not zero | |
if notif is not equal to "" then | |
display notification notif with title "RAM Overuse!" | |
end if |