I am trying to track the occurrences and duration of power outages. I have my computer(Mac High Sierra) powered by a UPS and set to shutdown when there is an outage. I have an applescript that when run prints the time and date to a text file and am able to get that to run on start up. However, I am unable to get it to work when the computer shuts down. I have tried using launchd and logout hooks to no avail. How should I go about this?

New contributor
Bjorn is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • Since you are already running a script at startup, just add the following example AppleScript code to your script to get the date and time the Mac last shutdown and process the result as wanted. set lastShutdown to (do shell script "last | awk '/^shutdown/{print $3,$4,$5,$6; exit}'") – user3439894 Sep 11 at 16:18
  • Thank you @user3439894 That is exactly what I needed. – Bjorn Sep 12 at 14:31

Your Answer

Bjorn is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.