Launch Google Chrome Incognito from the terminal or a shortcut in OSX

Problem: Ok not really a problem, but I want to be able to launch Google Chrome straight to Incognito mode from a shortcut. This is useful when logging into multiple bank accounts, Google Apps accounts, or testing session based websites. etc etc etc.

Fix: Thankfully the Google Chrome.app can be launched with the –incognito switch to do just that. The terminal command to do this, assuming the browser is sitting in /Applications/ is this:

open -a /Applications/Google Chrome.app --args --incognito

Note: –args has to be passed to satisfy the ‘open’ command’s arguments first.

Launching it from a shortcut: If you want to create a shortcut to do this, open AppleScript Editor and enter the following:

tell application "Terminal"
	activate
	do script "open -a /Applications/Google\ Chrome.app --args --incognito;"
	delay 1
	quit
end tell

Note: The space in the Google Chrome.app name must be double-escaped with two backslashes like that to work. Also, without the delay I found that the script exits too quickly or something like that, and it doesn’t work.

Save the above script as an Application, and call it something like ‘Incognito’. Running this app will launch Terminal, Chrome Incognito, then exit Terminal. Bingo!

Giving your Incognito app an Icon: I’ve added the app to my Dock, and given it a special icon (see below for a downloadable PNG icon). To do this:

  • Open the image you want to use as the icon – it should be a 512×512 24bit PNG if possible – and copy the image to the clipboard. If you are using Preview to view the image, do cmd+a to select all, then cmd+c to copy it… this works for most other graphics packages also.
  • Locate the app you created above in Finder, then press cmd+i to bring up the info window (alternatively right-click the app then select ‘get info’).
  • In the resulting pop-up, click on the icon at the top to highlight it like so (notice the blue halo around it):
    Original Script Icon
  • Then use cmd+v to paste the new icon from the clopboard into the icon area and it should look like this:
    New Incognito icon
  • Close the info window, and it’s done. You should now have a nice looking shortcut that opens Chrome Incognito with one or two clicks!

Feel free to use this icon. It’s just the standard one with some ‘colour replace’ work to make it blue. You could paste some tacky sun glasses over it if you wished 🙂

Quick ‘Lorem Ipsum’ plugin / extension for IE

Problem: While doing web development, I frequently need to insert lorem ipsum into a text field or textarea. To do this – bearing in mind that I don’t really like or use bookmarks, too messy – I tend to google “lorem ipsum”, hit lipsum.com, select/copy the block of text, and then return to my form field and paste it.

I wanted a quicker solution, and as I find myself using IE more and more to develop in now (thanks to the excellent ‘Developer Tools’ extension – never thought I’d say that!) my lorem ipsum fix would have to be in the form of an IE toolbar button or menu item.

Fix: It turns out that adding a simple javascript based text field filler option to a context menu is really easy, so that’s what I did. Here are the steps:

Firstly: Create the javascript to access the currently focused field, and insert the lorem ipsum text. Create a new html file in a location of your choice –  I used C:Program FilesInternet ExplorerPlugins – and copy the following code into it:

<script language="JavaScript">
var parentwin = external.menuArguments;
var doc = parentwin.document;
var rng = doc.selection.createRange();
rng.text = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
</script>

Save the file as loremipsum.htm.

Secondly: Create the registry entry for the menu item:

  1. Open/run ‘regedit’ (Start > run… > “regedit” > ‘Ok’)
  2. Use the tree to navigate to:
    HKEY_CURRENT_USERSoftwareMicrosoftInternet ExplorerMenuExt
    using the tree view on the left of the Registry Editor.
  3. Create a new key (Right click, “New” > “Key”) and call it “Lorem Ipsum” or anything you like.
  4. Inside the new key, open the ‘default’ string value that’s already there (double click on it), and enter the path to the script you created just now. i.e. C:Program FilesInternet ExplorerPluginsloremipsum.htm
  5. Now create a new DWORD value (Right click, “New” > “DWORD Value”) and rename it “Contexts”. Set the value to 0x04 (hex) or 4 (decimal). Here’s an explanation of the different values.
The new Key and values in RegEdit
The new Key and values in RegEdit

 

That’s it! Now open IE, find a textarea or text field, right click, and you should see something like this:

Note the new highlighted option in the context menu
Note the new highlighted option in the context menu