It’s a little weird to think about how long the “modern” incarnation of the internet has been around. I remember back in 2004 I was just a sophomore in high school. My friend excitedly told me that he had a handful of invitations to something called “Gmail.” It’s hard to imagine nowadays, but good webmail wasn’t a common thing back then. I remember how excited I was that it came with one whole gigabyte of storage! And it was always increasing! How could Google do that?!
Well that was over 10 years ago now. Gmail has changed a lot since then, but it’s still a very good webmail client. I still use the original account I created back in 2004. When I got my Macbook Air, though, I figured, might as well set up Mail and use that for email. Don’t get me wrong, Mail is a very capable program, and I love the way it integrates with OS X Yosemite. I was essentially “raised” on webmail clients though, which have always had a different feel from standalone desktop mail clients, so Mail feels arcane to me in many ways.
I decided to stop using Mail and switch back to using Gmail in Safari. Obviously that works really well, but there are certain things Mail could do that Gmail in Safari didn’t. I could get over all of them except for one: notifications. When new mail comes in, I want to know about it. OS X has a great notifications system and it seems a shame to not take advantage of it. The Mail app is obviously tied into OS X so it can push out notifications for new mail, but here’s something you may not know: Webkit, the layout and HTML rendering engine used by Safari, Google Chrome and many other browsers supports something called “webkitNotifications.” These are really cool. Basically, they are a way for pages within the browser to request permission of the operating system to push operating system notifications. These notifications are no different from the ones sent by Mail, or Messages, or any other OS X application.
Can you see where I’m going with this? Yes, you can enable these notifications for Gmail within Safari on OS X Mountain Lion and up. It requires a bit of tinkering to make it work in Safari, but it’s pretty easy to do. Google Chrome will pretty much do it by default, and I think Safari doesn’t do it out of the box because Google wants to push you into using their browser.
Here’s how to get notifications running.
- First, you need to enable the Develop Menu. You can do this by going to Safari > Preferences > Advanced and checking the “Show Develop menu in menu bar.”
- Next, visit mail.google.com and log into your account.
- With your Gmail account open, click the Develop Menu item and select “Show Web Inspector.”
- The Inspector console will now show on the bottom of the screen. If it’s not in console mode, just click the Console button on the top of the Inspector window.
- At the bottom of the console, there should be a little “>” symbol. This is where you can enter JavaScript and other commands to execute on the page. You want to paste the following JavaScript code into that box and press enter: window.webkitNotifications.requestPermission(function(){alert(window.webkitNotifications.checkPermission());})
- An alert box will pop up showing “0” which means that mail.google.com now has permission to send notifications to the operating system. Voila!
As long as you have Safari open (even in the background) with a Gmail tab or window running, you will receive notifications about new mail! As a bonus, just like all OS X notifications, you can change the style, behavior, etc. by opening System Preferences > Notifications and tweaking the settings for Safari.
This simple modification makes Gmail so much more usable within OS X. Now I can be on top of my new mail as soon as it comes in.