Backup Chrome tabs with JSTalk

Sometimes Chrome has trouble restoring its windows and tabs upon launch (the windows and tabs open, but their content never loads). The worst thing about this bug is that it tends to happen only when I have large number of windows and tabs to restore.

I’ve added the following JSTalk script to my nightly backup routine. It writes out the names and URLs of all open tabs to a text file:

var chrome = [SBApplication application:'Google Chrome'];
var windows = SBElementArrayToJSArray([chrome windows]);
var output = '';
windows.forEach(function(window){
    var windowName = [window name];
    if (windowName != 'New Tab') {
        var tabs = SBElementArrayToJSArray([window tabs]);

        output += windowName + '\n';
        tabs.forEach(function(tab){
            output += '\t' + [tab title] + '\n';
            output += '\t' + [tab URL] + '\n\n';
        });
    }
});

Date.prototype.getShortWeekdayName = function(){
    return ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'][this.getDay()];
};
var tabsBackupFileName = 'tabs_' + (new Date()).getShortWeekdayName() + '.txt';
var tabsBackupFilePath = [@"~/Documents/backup/browser" stringByExpandingTildeInPath];
tabsBackupFilePath = [tabsBackupFilePath stringByAppendingPathComponent: tabsBackupFileName];

[[NSString stringWithString:output] writeToFile:tabsBackupFilePath atomically:NO encoding:NSUTF8StringEncoding error:nil];

function SBElementArrayToJSArray(sbArray) {
    var sbIdx = 0;
    var sbCount = [sbArray count];
    var result = [];
    for (; sbIdx < sbCount; sbIdx++) {
        result.push([sbArray objectAtIndex:sbIdx]);
    }
    return result;
}

It uses Cocoa’s Scripting Bridge to enable JSTalk to talk to Chrome via its AppleScript interface.

chrome jstalk Apr 22 2012

“Search With Google” Using Chrome

About a month back I tweeted:

people of the Internet: how do I make Search With Google (Command-Shift-L) use Chrome (my default browser) instead of Safari?

Mark Rowe informed me:

“Search With Google” is a service provided by Safari.app. You’d need to create a new service and bind it to that key equivalent.

Working from Mark’s suggestion, I first disabled Safari’s Service by unchecking System Preferences > Keyboard > Keyboard Shortcuts > Services > Searching > Search With Google.

Then I launched Automator and created a new Service. I added a single Run Shell Script action like so:

Search With Google Automator Action

Here’s the text of the Ruby script to save you from having to retype it:

require 'cgi'
`open 'http://www.google.com/search?q=#{CGI.escape(STDIN.read.chomp)}'`

When you save your Automator workflow, Automator will ask you for a name for your service. I’ve unimaginatively named mine “Search With Google (Wolf)” to indicate it’s pretty much just like Safari’s built-in service, but tweaked by me.

Automator will automatically save your workflow into ~/Library/Services, but it’s up to you to assign your abandoned Command-Shift-L to your newly created variant.

To do so, find your new Service in System Preferences > Keyboard > Keyboard Shortcuts > Services > Text. Then double-click the column to the right of your Service and type Command-Shift-L set your shortcut.

safari chrome macosx automator May 24 2011

Chromium Honeymoon

Justin Williams / @justin:

Chrome:mac update: 3 days later and I am still in love. Fast, low resource usage, stable. A few features to go before perfection.

I’m not a tabbed-browsing guy: I liked to open a lot of windows in Safari. Crash-WindowServer-due-to-resource-exhaustion amounts of windows.

Problem is 10.6 some how has broken ⌘-` window shuffling (it now seems to have a weird time-based inverting behavior similar to ⌘-tab app switching).

I find myself using (and liking) tabs in Chromium because their ordering+navigation behavior is consistent, unlike lots-of-windows-in-Safari.

chrome Nov 10 2009

Chromium Extensions

Chromium is looking great from a plug-in developer’s perspective:

Thanks to Kevin Mitchell for enlightening me to all this coolness.

chrome Nov 3 2009

ClickToFlash on Chrome

ClickToFlash is a WebKit plugin. WebPlugIn plug-ins are new, based off a new Objective-C API.

Chrome/Mac currently supports the older Netscape CFPlugIn-based API, but not WebPlugIns. So it’s not just a matter of flipping an Info.plist flag or recompiling ClickToFlash to support Chrome — it may need a re-write.

I haven’t really looked yet so see what work it would take — we may be able to create a plug-in API bridge of sorts that allows ClickToFlash to target both browsers simultaneously (though you’d probably need to separate binaries).

I talked to Chrome’s plugin API engineer at WWDC09, and she’s down with ClickToFlash and wants to help us light it up. Happiness.

Interestingly, I think this would also give us Firefox support.

Update: Now it doesn’t look like we’d get Firefox support for free. Don’t really care, since I hear good things about Flashblock.

clicktoflash chrome Nov 2 2009