Jan 2, 2008
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.
Cron job? Shouldn’t it be a LaunchAgent since cron is depricated?
Good point. Will update it.
[...] the requested .plist file, insert your username (or the path where you’ve put the Apple Script) and save it to /Library/LaunchAgents/com.apple.tm-notification.plist. Then do launchctl load [...]
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.
Did you use the cron variant or launchd?
I used the launchd
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)
I don’t see any errors, and it actually seems to be working now.
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
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"}
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.
I just used codes tags on the above, but it seems to have had its way with the formatting. Sorry about that.
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.
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
GrowlHelperApp is mentioned in the script however its not found on my system. What was used to load Launchd with the log ’schedule’?
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).
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.
Nightstrike, did you copy it to the public folder in your user profile? Did you adjust the path to the .plist and .scpt file?
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.
You’re welcome, glad it’s helpful.
[...] Stop Being Carbon · Time Machine notification with Growl (tags: osx TimeMachine growl) [...]
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.
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
@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.
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?
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
no problem. did you save the .plist to /Library/LaunchAgents/com.apple.tm-notification.plist? Because it says that you didn’t.
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.
this might help :P http://tinyurl.com/6onawf
Honestly? I have no idea. Sorry.
ok, thanks anyway.
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 -5mif [ "$status" != "" ] ; then /usr/local/bin/growlnotify -n “Time Machine” -m “$status” fi
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
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!
More important than this would be a launctl remove name_of_the_script to remove the launch item. Or if you’re using the cronjob approach, please edit the cronjob file with crontab -e.
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
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 -5mif [ "$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 fiHi,
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
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?
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 ^
This is a great use for Prowl.
Now to get it going with Prowl notification plugin would pop this nicely on my iphone
I setup the script and plist as directed. When time machine runs a backup all I receive as Growl notifications is that the volume has been mounted and unmounted. I don’t receive any logs, etc. I also have an icon of a folder and not the time machine icon. Is the shell script still accurate?
If I remove the shell script and run a dummy text in it’s place I get the time machine icon and it registers with growl and works like it’s supposed to. Any help would be appreciated.
This is the script that gives me the wrong icon and does not register:
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 ¬ {“Time Machine Notification”}
end if
This dummy script does work properly (other than obviously telling me about what the time machine is doing:
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 ¬ {“Time Machine Notification”}
end if
I’m sorry, that dummy script should be:
–set consoletext to do shell script “syslog -F ‘$Message’ -k Sender /System/Library/CoreServices/backupd -k Time ge -5m” set consoletext to “this is a test” if console_text is not “” then tell application “GrowlHelperApp” set the allNotificationsList to ¬ {“Notification”}
end if
Would Growl work to notify me to eject my external devices (hard drive) before shutdown? Both my wife and I have had small to significant data corruption by not doing this. I would be so ever grateful and appreciative … Steve
Steve, You might be able to could use hardware growler for this http://growl.info/documentation/hardwaregrowler.php
Hi, I tried putting all of this in place by following all your steps. The Terminal says that it is loaded, but I do not get any notifications. Does this script still work for 10.6?
I dont thinks so. It used to work before i upgraded to snow leopard, but now its not.
I think the issue is with XSLT Tools.osax framework.
It is not compatible with 64 bit on 10.6.
Contact the developer http://www.latenightsw.com/freeware/XSLTTools/index.html
Last i heard he was going to fix it.
See if you get this in your console log.
11/29/09 8:59:45 AM AppleScript Runner[7840] Error loading /Library/ScriptingAdditions/XSLT Tools.osax/Contents/MacOS/XSLT Tools: dlopen(/Library/ScriptingAdditions/XSLT Tools.osax/Contents/MacOS/XSLT Tools, 262): no suitable image found. Did find: /Library/ScriptingAdditions/XSLT Tools.osax/Contents/MacOS/XSLT Tools: no matching architecture in universal wrapper
Ok, thank you I will look into that.