Skip to content

Instantly share code, notes, and snippets.

@prenagha
Last active December 8, 2023 23:16
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prenagha/8525643 to your computer and use it in GitHub Desktop.
Save prenagha/8525643 to your computer and use it in GitHub Desktop.
Applescript to monitor age of last time machine backup and send alert to notification center and email if too old Set it up in launchd to run daily
--
-- Applescript to monitor age of last time machine backup
-- and send alert to notification center if too old
--
set tmLatest to do shell script "/usr/bin/tmutil latestbackup"
set latest to POSIX file tmLatest
set mod_date to modification date of (info for latest)
set file_age to round (((current date) - mod_date) / days)
log "most recent TM backup " & file_age & " days old"
if file_age > 7 then
display notification "Most recent TM backup is " & file_age & " days old" with title "Time Machine Backups Not Running!!" subtitle "Contact Admin" sound name "Basso"
delay 1
set cn to computer name of (system info)
tell application "Mail"
tell (make new outgoing message)
set subject to cn & " TM Backup Fail"
set content to "Most recent " & cn & " TM backup is " & file_age & " days old"
make new to recipient at end of to recipients with properties {address:"admin@example.com"}
send
end tell
end tell
end if
@1-61803
Copy link

1-61803 commented Jul 31, 2016

I think this script would only work if you have an attached TM disk. Check this other script, http://www.fixitscripts.com/problems/script-check-time-machine-backups-and-report-how-long-since-last-good-backup-on-client-daily-report I found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment