Get a notification when RAM is using compressions or swaps on MacOSX

A scheduled AppleScript to notify when RAM on mac is using compression or swaps. This is useful to find out when your mac gets less responsive so you can take appropriate measures, or when you have SSD installed as swaps reduce its life.

March 17, 2017 - 2 minute read -
#macosx #hack

When you have not shut down your mac for a long time and are using a lot of different stuff like having multiple tabs opened in the browser, your RAM tends to get filled.

After some time, it’ll start to use compressions to store old data in RAM to make way for fresh data. And after that, it’ll start to use swaps on your hard disk.

This usage of swap results in a lot of reads/writes in the hard disk, which can result in less responsive mac in case of HDD and shortening of life in SSDs.

This is a script you can schedule to run however and whenever you want using crontab and applescript. It checks various RAM stats like compressions and swap usage and notifies when they are being used.

Currently, it’s scheduled to run every hour and to check these RAM parameters-

  • Compressions
  • Decompressions
  • Swapins
  • Swapouts

Here is the gist with the code. Just download the applescript file, and set it up using crontab



References

Crontab.guru
AppleScript Programming - Wikibooks
xRahul/RAM_Overuse_Notification.applescript - Github Gist
Introduction to AppleScript - Apple Developer Documentation
Introduction to AppleScript Overview - Apple Developer Documentation
Introduction to AppleScript Language Guide - Apple Developer Documentation
How can I configure my computer to run an AppleScript at a specific time? - Stackexchange