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?

  • 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 '19 at 16:18
  • Thank you @user3439894 That is exactly what I needed. – David House Sep 12 '19 at 14:31

Your Answer

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.