Latest in Applescript

Image credit:

Use AppleScript to open current Safari URL in Google Chrome

TJ Luoma, @tjluoma

I've been using John Gruber's suggestions from Going Flash-Free on Mac OS X, and How to Cheat When You Need It to avoid installing Adobe Flash by using Google Chrome (which includes its own version of Flash) whenever I run into a page that has Flash I want to see.

To make this easier, John suggested turning on the "Develop menu" in Safari's "Advanced" preferences, which includes a sub-menu to "Open Page With" and a sub-sub-menu that shows all of your installed browsers. John suggested using System Preferences to create a keyboard shortcut for "Google Chrome" or "Google" depending on which one you saw in the menu.

Unfortunately, this failed for me quite often. Every time I launched Safari, the keyboard shortcut would not work until I had opened that menu manually using the mouse. I hate using the mouse. After opening the menu, the keyboard shortcut would work until I quit Safari again. That was mildly annoying, but things recently took a turn for the worse.

Here's what the menu looks like for me now:

Notice that the browser listings now include version numbers. This means that a keyboard shortcut would have to include the version number, which means it would break whenever the browser is updated.

I asked a few folks, and it appears this changed in Safari 5.0.4. I haven't been able to find a way to revert to the old behavior, so I started looking for another way.

Enter AppleScript

Using AppleScript, you can send the current URL from Safari to Google Chrome.

Here is the AppleScript that I am currently using:

(Note: this article was updated on 2013–02–10 to include an updated and improved version of the AppleScript, as well as expanded instructions on how to use it.)

This AppleScript will launch Google Chrome if it is not already running, and will not overwrite any existing tabs in Google Chrome.

To use this AppleScript, you will need to download it from Github. Note that the download filename will be something ridiculously long which starts with 'gist4750810' (don't ask me why, it's a Github 'thing'). Find that file in your Downloads folder, double-click it, and Archive Utility will open it and show you a folder with a file named 'Open in Google Chrome.scpt' in it.

Now you'll want to open a new Finder window so you can navigate to where that file needs to be installed, so choose File » New Finder Window and then move on to the next section.


To use 'Open in Google Chrome.scpt' in Safari, it needs to be installed to ~/Library/Scripts/Applications/Safari/ (where ~ is the path to your Home directory).

If that folder does not exist, you will need to create it. The easiest way to do this is to go to the Finder and then choose the "Go to Folder..." option from the Go menu, as shown here:

Once you have done that, a window will appear prompting you to enter the path that you want to go to. Enter


and see if it opens the folder.

(Aside: If it says "The folder can't be found" try going to ~/Library/Scripts/Applications/ instead, and then just create the 'Safari' folder using File » New Folder from the menu bar.)

Once you are in the ~/Library/Scripts/Applications/Safari/ folder, simply drag the 'Open in Google Chrome.scpt' file to it from the other Finder window.

Using 'Open in Google Chrome.scpt' From Safari

Once 'Open in Google Chrome' is installed, there are two ways to use it from Safari.

Option one is to use the "Scripts" menu extra from OS X. Option two is to use a program called FastScripts. I prefer FastScripts, but will explain how to use the standard OS X option first.

To use that Scripts menu, launch the "AppleScript" found in /Applications/Utilities/ and then go to Preferences and enable the option 'Show Script menu in menu bar' as shown here:

Once the Script menu is enabled, you will see 'Open in Google Chrome' whenever you are in Safari. Just click on the Scripts icon in the menu bar and select it as shown here:

But what if you want to use a keyboard shortcut instead of the mouse? For that you will need FastScripts, which gives you everything the standard 'Scripts' menu offers, plus the ability to assign keyboard shortcuts.

To assign a keyboard shortcut, open FastScript's preferences and find the entry for 'Safari' under your home folder, then locate the 'Open in Google Chrome' entry. Click over in the 'Shortcut' column and assign it a keyboard shortcut. As you can see here, I have chosen (Option) + G:

FastScripts lets you assign up to 10 keyboard shortcuts for AppleScripts for free. If you want to use more than 10, you'll need to buy a license for US$15. As a keyboard-lovin' mouse-hater, I consider that a bargain. FastScripts offers a lot more than just keyboard shortcuts, so I would encourage you to check it out.

"Flash Free"

Now whenever I am in Safari and encounter a page which requires Flash, I press ⌥ + G and the page loads in Google Chrome. It's quick and easy, and doesn't require that I maintain a separate Flash installation.

Adobe Flash continues to be a source of security problems. Using it in only Google Chrome is a good way to increase your browsing security, especially since Chrome is frequently updated.

p.s. since I know there are many other Keyboard Maestro fans out there, I'll also add a quick link to my Keyboard Maestro macro for doing this same thing using Keyboard Maestro.

From around the web

ear iconeye icontext filevr