Time Machine notification with Growl

Time machine is really a fine piece of software. The only thing which is missing is some kind of notification when a backup was done (you can open the preferences, but that’s not really satisfying).

So I crafted some little Apple Script:

set console_text to do shell script "syslog -F '$Message' -k Sender /System/Library/CoreServices/backupd -k Time ge -5m"
 
if console_text is not "" then
	tell application "GrowlHelperApp"
		set the allNotificationsList to {"Notification"}
		set the enabledNotificationsList to {"Notification"}
 
		register as application ¬
			"Time Machine Notification" all notifications allNotificationsList ¬
			default notifications enabledNotificationsList ¬
			icon of application "Time Machine"
 
		notify with name ¬
			"Notification" title ¬
			"Time Machine" description console_text ¬
			application name "Time Machine Notification"
 
	end tell
end if

Copy it to some folder and register a cronjob, something like this: */5 * * * * /usr/bin/osascript /Users/[username]/Public/tm.scpt

Here is the compiled script: Time Machine Notification

If you want to have a shorter/longer interval you need to change the cron line accordingly and the script (it’s the last parameter in the first line, now saying ‘5m’).

Edit: I did what a reader suggested, here is the .plist file.

Tags: , , ,

  1. T.’s avatar

    Cron job? Shouldn’t it be a LaunchAgent since cron is depricated?

  2. Christoph’s avatar

    Good point. Will update it.

  3. Jon’s avatar

    I tried this script, and it worked wonderfully, however it only worked once. Subsequent backups have not been shown. Do you have any ideas of why this would be? Thanks.

  4. Christoph’s avatar

    Did you use the cron variant or launchd?

  5. Jon’s avatar

    I used the launchd

  6. Christoph’s avatar

    Sorry for not replying the last few days, my Mac got a new display. Do you see any errors in the console? (should list as tm-notification)

  7. Jon’s avatar

    I don’t see any errors, and it actually seems to be working now.

  8. Fred’s avatar

    I used the above script and it worked great, but I found it pumped out more information than I needed, so I added some code to exclude some log statements that seemed redundant.

    [code lang="applescript"] set consoletext to do shell script "syslog -F '$Message' -k Sender /System/Library/CoreServices/backupd -k Time ge -5m" set modText to trimparagraphs(consoletext) on trimparagraphs(thistext) set the paragraphlist to every paragraph of thistext set the newlist to {} set path_count to 0

    repeat with i from 1 to the count of paragraphs of thistext set thisparagraph to item i of the paragraphlist if thisparagraph contains "automatic scheduler" then else if thisparagraph contains "No pre-backup thinning needed:" then else if thisparagraph contains "Trusting backup" then else if thisparagraph contains "getting cat info" then else if thisparagraph contains "Mounting disk image /Volumes/Backups/" then else if thisparagraph contains "Starting post-backup thinning" then else if thisparagraph contains "Trusting backup" then else if pathcount > 0 then -- do nothing else if thisparagraph contains "Disk Image Mounted" then set the end of newlist to "Disk Image Mounted" set the end of newlist to this_paragraph

      else if this_paragraph contains "rebuild path cache" then
          set path_count to 1
          set the end of new_list to this_paragraph
      else
          set the end of new_list to this_paragraph
      end if
    

    end repeat

    set AppleScript's text item delimiters to return set mod2 to new_list as string set AppleScript's text item delimiters to "" return mod2

    end trim_paragraphs

    if modText is not "" then tell application "GrowlHelperApp" set the allNotificationsList to {"Notification"} set the enabledNotificationsList to {"Notification"}

    register as application ¬
      "Time Machine Notification" all notifications allNotificationsList ¬
        default notifications enabledNotificationsList ¬
        icon of application "Time Machine"
    
    notify with name ¬
      "Notification" title ¬
      "Time Machine" description modText ¬
      application name "Time Machine Notification"
    

    end tell

    end if [/code]

    I also just used Lingon to set it to run every 5 mins. Thanks a bunch for the script, it was driving me crazy not having updates on the TM status.

  9. Fred’s avatar

    I just used codes tags on the above, but it seems to have had its way with the formatting. Sorry about that.

  10. Christoph’s avatar

    Thanks for the script, Jon. I tried to put clean up your comment (Wordpress really sucks at posting code as a comment). It’s quite okay now, I guess.

  11. Fred’s avatar

    Thanks, for cleaning it up, but it’s still quite messed with html tags and such, so I posted a copy at http://fredandtanya.com/files/GrowlTimeMachineNotification.scpt

  12. G’s avatar

    GrowlHelperApp is mentioned in the script however its not found on my system. What was used to load Launchd with the log ’schedule’?

  13. Christoph’s avatar

    G, you need Growl installed. What do you mean with your second question? You just need to execute launchctl load /Library/LaunchAgents/com.apple.tm-notification.plist and it should be done (adding the file at first, of course).

  14. Nightstrike’s avatar

    Hey, I’m not very good at the technical side of all this. I downloaded the script, just put it in my User folder, and then created the plist file and put it where you said I should. I then inputted that command into Terminal, and it acccepted it. But then, I tested it by running a back up, and no notification showed up. Clearly I’m missing an obvious step… can you tell what it is? I have Growl, so that’s not the problem…

    Thanks so much.

  15. Christoph’s avatar

    Nightstrike, did you copy it to the public folder in your user profile? Did you adjust the path to the .plist and .scpt file?

  16. Nightstrike’s avatar

    Hey actually I fiddled around a bit and realised that I didn’t change the path. It’s now working perfectly (so great work!) Thanks so much.

  17. Christoph’s avatar

    You’re welcome, glad it’s helpful.

  18. scott’s avatar

    hi, sorry to add a comment so late after the last, but i’m quite interested in this but need some help, hope it’s ok.

    i’d love to have growl notifications for time machine but i have to admit that i know nothing about using scripts or registering cronjobs.

    could someone please give me a simple step-by-step on what to do? i hate to sound like an idiot but i do need basically everything explaining to me about this.

  19. Macroscopic’s avatar

    Nicely done. I’ve got the .plist and growl notifications up and running swell on a 10.5.4 client machine. The Time Machine Notification app lists properly in the Growl Pref Pane and I enables the MailMe plug-in to receive email notifications. Ubür-sweet. However, practicing the identical installation technique I’ve hit a block installing on 10.5.4 Server. All looks correct but the Time Machine Notification app doesn’t appear in the Growl Apps list so I can’t configure it. Poo.

    Any ideas if launchd performs vastly different in the server implementation?

    Thanks

  20. Christoph’s avatar

    @Scott

    First you need to take the above Apple-Script and save it to some place (your public directory should be fine). Then you take the .plist file (which you can find here and save it under /Library/LaunchAgents/com.apple.tm-notification.plist. Then you execute the bash line mentioned in the article – launchctl load /Library/LaunchAgents/com.apple.tm-notification.plist. That should be it.

    @Macroscopic Nope, sorry, absolutely no experience with Mac OS X Server.

  21. scott’s avatar

    thanks christoph, but this hasn’t worked. after i do everything you said, this is what terminal says after the bash line:

    http://farm4.static.flickr.com/3265/2796989366186fd592e2o.png

    what do you think i could be doing wrong?

  22. scott’s avatar

    p.s. sorry about that dodgy link, not sure why only half of it is clickable. here’s a tiny url for it :) http://tinyurl.com/5zdtlo

  23. Christoph’s avatar

    no problem. did you save the .plist to /Library/LaunchAgents/com.apple.tm-notification.plist? Because it says that you didn’t.

  24. scott’s avatar

    i think i did, well, what i did at first was make the file in textedit then try and save into launchagents but it said access denied, so i saved it to desktop then dragged into launchagents.

    here is a screenshot of the file, and the file shown in the launchagents folder in finder.

  25. scott’s avatar

    this might help :P http://tinyurl.com/6onawf

  26. Christoph’s avatar

    Honestly? I have no idea. Sorry.

  27. scott’s avatar

    ok, thanks anyway.

  28. swiney’s avatar

    I figured out how to do this without applescript… The growl package comes with an optional command-line tool called growlnotify. If you install that, you can run this shell script from launchd, and it will do the job

    !/bin/sh

    status=syslog -F '$Message' -k Sender /System/Library/CoreServices/backupd -k Time ge -5m

    if [ "$status" != "" ] ; then /usr/local/bin/growlnotify -n “Time Machine” -m “$status” fi

  29. swiney’s avatar

    grrr… your comment system took out all of my carriage returns and backticks… the script won’t run as it shows up in my last comment

  30. Nightstrike’s avatar

    So, it’s been a while, and this script was great, but since there’s now the menubar icon for time machine, I don’t think I really need it. Can I just delete the scpt and plist files and then I’ll be all set? Or is there something else that I’ll have to do in order to make a clean deinstallation. Thanks!

  31. Christoph’s avatar

    More important than this would be a launctl remove ofthe_script> to remove the launch item. Or if you’re using the cronjob approach, please edit the cronjob file with crontab -e.

  32. Nightstrike’s avatar

    Hi again, how do I do the removal of the script? I put in launctl remove /Users/Dan/Public/tm.scpt and got an “command not found” error. I looked online and found that it should have been (?) launchtl remove, but that too was not found on my computer. Any thoughts? Thanks for your help

  33. Arnold Nefkens’s avatar

    Well, tried the cli version. But did not work straight away… Took some time to figure out what went went wrong.

    Solution:

    !/bin/bash

    status=/usr/bin/syslog -F '$Message' -k Sender /System/Library/CoreServices/backupd -k Time ge -5m if [ "$status" != "" ] ; then /usr/local/bin/growlnotify -n “Time Machine” -m “$status” –image /System/Library/PreferencePanes/TimeMachine.prefPane/Contents/Resources/TimeMachineGraphic.png > /dev/null 2>&1 fi

  34. Takuma Habu’s avatar

    Hi,

    I was trying to use Nefkens solution but I have no idea where to run that command… I have managed to install growlnotify by simply running “./install.sh” it now says “add /usr/local/bin to you PATH” but I’m hoping that’s already been done…

    But what do I need to do next? Tak

  35. David Chambers’s avatar

    Great work! I’m curious: Would you mind explaining the purpose of the ‘5m’ in the script? Does this determine how frequently the script runs?

  36. Simon PIerre Desrosiers’s avatar

    Ha looks great, but syslog crashes on me on my machine

    [ Cassandre:: 20:51] [~] # syslog -F ‘$Message’ -k Sender /System/Library/CoreServices/backupd -k Time ge -1m syslog(89548) malloc: *** error for object 0×107cc0: double free *** set a breakpoint in mallocerrorbreak to debug Segmentation fault [ Cassandre:: 20:51] [~]

    And any variation on the syslog commands also segfault.

    Any one has a clue ^