Stop Chrome from adding extra tab when opening links
April 14, 2011 10:51 AM   Subscribe

Help me stop Google Chrome (Mac OS X) from creating a superfluous tab when opening for the first time with an external link.

I’ve been using John Gruber’s wonderful suggestion on his blog Daring Fireball ( see CHEATING WITH GOOGLE CHROME) for removing the Flash plugin from my Mac and using a hotkey to open a link in Chome when Flash is needed.

The tip uses a script from TJ Louma that opens a link in Safari in Chrome to view with Chrome’s built-in Flash.

The problem is that when using this script, or even when you drag a link onto the Chrome application icon, Chrome opens a blank tab and a tab containing the link requested.

So, anyone know how to keep Chrome from opening an unnecessary tab when starting up from an external link (dropped on the app icon, through a hotkey, or otherwise)?
posted by qwip to Computers & Internet (6 answers total) 3 users marked this as a favorite
 
Use this script instead and it will work without opening any extra windows or tabs. (If you have Chrome in a non-standard location, edit the path in the 'do shell script' statement.)
property theURL : ""
tell application "Safari"
    set theURL to URL of current tab of window 1
end tell
do shell script "/Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome " & theURL

posted by pmbuko at 2:13 PM on April 14, 2011


Note, this will not work if Chrome is already open. Unfortunately, sending any further pages/tabs to it will fail.
posted by pmbuko at 2:22 PM on April 14, 2011


Response by poster: Hmmm, not a huge improvement if it fails when Chrome is already open. The extra tab isn’t that inconvenient. Thank you for the option, it is appreciated.

Is there anything I can do on the Chrome side of things that tells it to stop starting with a superfluous blank tab, regardless of how I call a link? I’d prefer to handle it without resorting to a script, as I dislike the behavior when I drag a link onto the dock icon as well.
posted by qwip at 3:47 PM on April 14, 2011


Best answer: This was really bugging me, so I worked at it a bit. This applescript should handle all cases when you send it a URL from Safari:
property theURL : ""
tell application "Safari"
    set theURL to URL of current tab of window 1
end tell
tell application "System Events" to set procList to (name of every process)
if (procList contains "Google Chrome") then
    tell application "Google Chrome"
        if exists window 1 then
            tell window 1 to make new tab with properties {URL:theURL}
            activate
        else
            make new window
            set URL of active tab of window 1 to theURL
            activate
        end if
    end tell
else
    tell application "Google Chrome"
        if exists window 1 then close
        set URL of active tab of window 1 to theURL
        activate
    end tell
end if
Now, to handle drag-and-dropped links to the dock icon, I tweaked this script to accept drag-and-dropped links. First save this script as an application.
on open theURL
    tell application "System Events" to set procList to (name of every process)
    if (procList contains "Google Chrome") then
        tell application "Google Chrome"
            if exists window 1 then
                tell window 1 to make new tab with properties {URL:theURL}
            else
                make new window
                set URL of active tab of window 1 to theURL
            end if
        end tell
    else
    tell application "Google Chrome"
            if exists window 1 then close
            set URL of active tab of window 1 to theURL
        end tell
    end if
end open
tell application "Google Chrome" to activate
Next, Get Info on Google Chrome, then select and copy its icon. Get info on the application script you just saved, select its icon and paste Chrome's icon over it. Now put this script in the dock in place of Google Chrome. It will still launch Chrome if you click/double-click it without dragging a link onto it.
posted by pmbuko at 8:05 PM on April 14, 2011 [1 favorite]


Best answer: Sorry, one more tweak. The second script above was not handling dragged links properly. I fixed it by changing the first line and adding a new second line. The first three lines should looks like this:
on open theWebloc
    tell application "Finder" to set theURL to location of internet location file (theWebloc as text)
    tell application "System Events" to set procList to (name of every process)
I'm calling it done.
posted by pmbuko at 8:20 PM on April 14, 2011


Response by poster: Thanks, pmbuko!
posted by qwip at 4:20 AM on April 15, 2011


« Older Letters to a friend in prison   |   I want to know everything about cocktails: making... Newer »
This thread is closed to new comments.