So I got curious about how much value I've gotten from my Mac and decided to write a script that would tell me how many hours per day I've averaged since I got it, as well as how many days I've had it.
The final script isn't perfect but it's on npx so you can run it directly from there by just doing npx mac-usage-stats
.
You can view the code on Github.
Unfortunately there is one tiny dependency, but there's a chance you have it installed already. It's a command line tool for Mac that helps you get hard-drive info called smartctl, which you can install very easily.
Alternatively if you prefer, I originally wrote it in Python and you can use that too!
I find it really interesting to know how much I've used my Mac over four and a half years, and now you can too! βΊοΈ
Top comments (4)
You say it only works on Macs, but smartmontools is available across many OSs. I can do the same thing on my Arch machine with
smartctl -a /dev/sda
for example. This falls down a little because you're unlikely to ever change the drive in a Mac (because you pretty much can't) whereas in a regular PC you can move it from one machine to the next.Your
timeSinceBought
is also based on the date the setup finished. Won't that get reset every time you have to reinstall MacOS?Hey! Yeah you're absolutely right and I figured the same thing about changing drives so I only mentioned it as a Mac thing. Also true about the reinstalling but I don't think there's anything we can do about that, though PRs are always welcome π
Mmm, I've been looking at this. My mac doesn't have the same output from
smartctl
as you, so it tells me it's been on for 0 hours.I see it formatted like this:
Fiddling with knobs has given me the following which might work for most systems:
I'm using
mount
to get the drive associated with the root file system (which it likely to be the oldest drive in the machine), and then checking for both variants of label.smartctl
needs to be run as root on Linux, so something like this could handle both without unnecessarily elevating privileges on MacOS:I'm not going to build a PR because frankly I have no idea how this will work on other people's environments!
I made it work with linux on my machine, relying on
tune2fs
which will only work with ext3/4 filesystems, and I get this:Which is perhaps unhelpful...