Tuesday, August 31, 2010

Run Multiple Google Chromes with different profiles on a Mac

UPDATE: Google Chrome Beta (starting from v16) now supports multiple profiles. It allows almost the same thing that this article describes below. See the announcement about it in the Google Chrome blog.

If you have multiple accounts in different sites (GMail, Picasaweb, etc) and ever wondered how you can be logged in into both in your favourite Google Chrome browser, then I have a nice solution for you.

Of course you can use the Incognito mode to enter the credentials of a second account, but it is not preserved accross sessions. After a while providing the credentials over and over becomes boring.

I've read a little on how to run multiple Google Chrome instances on a Mac and found this wiki. I used it for myself and shared the link. While this is a good starting point, my friends started to complain that things did not work as they expected, so I decided to write my own tutorial on how to run multiple Google Chrome instances on one Mac:



Step 0: Install Google Chrome

I guess you already have Google Chrome installed. If not, install it from here. From now I will assume that it is in your /Applications folder.

Step 1: Create a shell script to launch a custom Chrome instance

Copy the following text into a file and name it as /usr/local/bin/custom_chrome.sh (or download it from here):
#!/bin/sh
if [ -z "$1" ]; then
  echo "Usage: $0 profile_name"
  exit 1
fi
PROFILE_NAME="$1"
GOOGLE_CHROME="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
USER_DIR="/Users/$USER/Library/Application Support/Google/Chrome/${PROFILE_NAME}"

exec "$GOOGLE_CHROME" \
  --enable-udd-profiles \
  --user-data-dir="$USER_DIR"
Make this file executable: in Terminal, run: sudo chmod +x /usr/local/bin/custom_chrome.sh

Step 2: Create your own Google Chrome application

Let's create a new profile "corp" and name your new application "Google Chrome (corp)".

For this, you have to open the terminal and do the following steps:

$ sudo bash
Password: your_password
# cd /Applications
# APPNAME="Google Chrome (corp)"
# mkdir -p "$APPNAME.app/Contents/MacOS"
# cd "$_"
# echo -e '#!/bin/sh\nexec /usr/local/bin/custom_chrome.sh corp' > "$APPNAME"
# chmod +x "$APPNAME"
# cd /Applications
# chown -R your_username "$APPNAME.app"
# exit

Now you have another Chrome instance with a profile which is independent of the main application profile!

Step 3: Make a custom icon for this application

The default icon of a new application is not really nice, so you can either copy the icon from Chrome, or download a custom one.

Google Image Search for "chrome icon" gives you a bunch of beautiful icons. In this article, I used the Chromium logo, the image from this techreviews page, a neon-style icon and an icon from this forum post.

To install a custom icon, the first, you have to select the application in Finder, then click on "Get Info":


Now open your selcted icon with your browser, and drag the image into the Icon in the "Get Info" page:


Note, that Google Chrome sometimes changes its icon back to the original icon when it is running and as far as I know the only way to change it back is to restart the browser.

Step 4: Enjoy the result of your work

Now you can drag your new Google Chrome (corp) application to your Dock and watch it running parallelly with the original application.

42 comments:

  1. I can't get this to work. When I try yo launch my new profile, it just disappears.

    ReplyDelete
  2. I had renamed my original Google Chrome.app. That was the problem

    ReplyDelete
  3. Nice post, I had found that other article as well but I like the finishing touches you added. I'm running 3 different versions of Chrome: beta, dev and release. I ended up going with this icon for release: http://treelz.deviantart.com/art/Worn-Chrome-icon-102191222

    ReplyDelete
  4. Hi Robert! Thanks for the info. The icon looks nice!

    ReplyDelete
  5. /usr/local/bin/ doesn't exist on my machine... did you have to create it? Is there a reason not to just put it in /usr/bin/?

    ReplyDelete
  6. Hi Prefusion,

    Feel free to use /usr/bin instead of /usr/local/bin. The idea behind /usr/local is that you usually put stuff there which are installed separately and not by the system, so that you can backup and restore everything by just copying that directory and reinstalling everything else.

    Balázs

    ReplyDelete
  7. Hey - looks like a neat solution - one Q - does this completely separate cookies, usernames etc?

    ReplyDelete
  8. Hi Huddo,

    Yes, they are entirely separate. This is the main point.

    Balázs

    ReplyDelete
  9. when i try and save the script it gives

    syntax error
    Expected “,” or “]” but found “"”.

    ReplyDelete
  10. Strange error. I edited the blog entry to contain a link to the script: http://patches-dlux.googlecode.com/files/custom_chrome.sh . Can you pleast try to download that?

    ReplyDelete
  11. I'm lost... do I need to change text in the custom_chrome.sh? For some reason the new link doesn't work.

    ReplyDelete
  12. @Erik: no, you don't. The new link (in the blog entry itself) should pop up a download window. But if you copy-paste the URL from the comment, it should work as well. What is it doing for you?

    ReplyDelete
  13. Works a treat. Just a pity spaces does not recocgnize the Google (corp). Any way to do that? Now it opens in the same space as the normal chrome does.

    ReplyDelete
  14. @Daniel: Sorry, I don't know how to make Spaces think this is a separate application... :(

    ReplyDelete
  15. This is a fantastic tutorial. Worked like a charm!

    Have you ever figured out a way to get the icon to stop changing back to the default? This is the ONLY drawback to this amazing tutorial (and totally not your fault).

    ReplyDelete
  16. This is a great hack. One problem that I ran into is that extensions that are installed on the client side by local software (e.g. 1Password) only go to the original user. The best workaround I found was to have the secondary Chrome user open the extension within the primary user account. To do this, select Window>Extensions in the Chrome menu and select the plus sign by developer mode. Click "upload unpacked extension" and Navigate to User/Library/Google/Chrome/Default/Extensions. Chrome assigns a random character string to each extension, but if you select the right extension within that directory it will be available to the secondary user account. I don't know whether this will update properly like other extensions, but it seems to be working.

    ReplyDelete
  17. Hi Ryan,

    Usually you can download any extension and install them through the Chrome Extension database to every different instance.

    1Password is an exception, because they did not provide an URL to the extension and the 1Password software supports installing to the first instance only. After an email exchange with their support, I got the URL. So installing the 1Password extension can be done by navigating to http://aws.cachefly.net/aws/dmg/1PW3/English/OnePasswordChrome.crx . The advantage of this is that it auto-updates itself, unlike the manual install method.

    ReplyDelete
  18. I suspect this can be done with a single .app - perhaps even posted as a single item to download. I'll experiment with it in a bit.

    ReplyDelete
  19. That's really useful! Thanks!

    ReplyDelete
  20. Hello. Just tried this on OSX Lion, but doesn't seem to work. Getting an error Exited with code: 126 as reported by com.apple.launchd.peruser.501

    ReplyDelete
  21. Sorry, I don't have Lion, so I cannot test it.

    ReplyDelete
  22. The second script doesn't require superuser.

    My suggestions:
    http://pastebin.com/cKqYN26K

    ReplyDelete
  23. Indeed, it does not require a superuser acc.

    Btw, I propose using the new profiles feature of Google Chrome Beta, that is much easier to use: http://chrome.blogspot.com/2011/11/take-your-chrome-stuff-with-you-in-new.html

    ReplyDelete
  24. im having a hard time getting the file to /usr/local/bin anytime i try using terminal to move a file there it says permission denied. Im new to this coding stuff, can you please help me

    ReplyDelete
  25. @karan: You can try the new profiles function of Beta version of Google Chrome as linked in the comment just above yours.

    For your problem: you have to be root to write to /usr/local/bin. If you don't know how to get root, you can use another directory in your home.

    ReplyDelete
  26. So I'm not a fan of the user profiles...I had this set up and working on Lion wonderfully...but, mac go boom...I did get a new mac (which is great) but this isn't working for me anymore? In my console I'm getting:com.apple.launchd.peruser.501[122] ([0x0-0x171171].Google Mobious[5642]): Exited with code: 1

    Any thoughts?

    ReplyDelete
    Replies
    1. No idea, what the problem can be. I don't use this recently. But why the built-in multi-profile setup is not good for you?

      Delete
  27. I'm a web dev, and it's mostly for being able have 3 different windows open that I can switch quickly with and see in my dock...I keep a LOT of tabs open for different projects, different accounts, different logged in status's. With this, I could use diff icons so I could quickly alt-tab to the instance I needed at that time...sigh, old habits die hard ya know?

    ReplyDelete
    Replies
    1. You can try to use the Cmd+~ instead of Cmd+Tab with multiple Chrome profiles.

      Sorry, I don't know what the problem is with the multi-profile setup. Actually I still have one instance what is run this way and it still works on Snow Leopard.

      Delete
  28. my sync doesnt work on second browser
    write me:
    "You already have data that is encrypted using a different version of your Google Account password. Please enter it below."
    how fix it ?

    ReplyDelete
    Replies
    1. Hi,

      It does not seem to be related to this topic.

      You must provide the right password for encryption for your second account. If you don't have it, then it is better to erase all the synced data in Privacy Dashboard (I think the message provides a link for that), then re-sync from the profile that still works and choose a password that you remember.

      In theory there might be a way to retrieve the password from the already working profile, but I'm not aware of that. I'd suggest to:

      1, Stop syncing on the already existing account.
      2, Remove data in the Privacy Dashboard
      3, Restart syncing on the already existing account with the password you choose.

      After that you'll be able to set up syncing in the second profile with the password.

      Balázs

      Delete
  29. If you're interested in creating application shortcuts similar to what Fluid does but using Chrome, checkout this article: http://lifehacker.com/5611711/create-application-shortcuts-in-google-chrome-for-mac-with-a-shell-script

    ReplyDelete
  30. Thanks for this tip which allowed my wife and I to have two separate instances of Chrome on the same user account.
    Take care to make /usr/local/bin/ directory also readable for your current user.

    ReplyDelete
  31. Does anyone know how to create separate icons for each profile for a PC?
    (I assume some of this approach has changed with the newer versions)

    ReplyDelete
  32. Hi! This is working great for me, but when I switch between profiles using CMD+TAB, the icons are the same, so I have no idea which one to choose. ANy ideas? Thanks

    ReplyDelete
  33. Well, sorry, I don't know. Chrome updates its icon time to time (for example at download).

    I'd switch to using Profiles instead.

    ReplyDelete
  34. In Mavericks you change the icon in this way: http://www.chrislangille.com/how-to-change-mac-application-icons-in-osx-mavericks/

    ReplyDelete
  35. Thanks for this post, worked like a charm :) But I have a problem - I use an app called Snap that gives me shortcuts to open Apps in the Dock. For ex. Alt+1 will open the first app I have in my dock. When I open the Chrome created with this method, it always opens a new window instead of bringing the already running window to the front. How to solve this issue?

    ReplyDelete
  36. Hi Swami,

    Sorry, I don't really know. Keep in mind, it is a hack, with limited usability. I still use it sometimes, but I use profiles, too.

    Try to contact the authors of Snap, maybe they can special-case Chrome profiles this way.

    ReplyDelete
  37. Hi, thanks for offering this trick. This is the closest solution to fit what I was looking for. However, one there's only one feature I can't access, which is : assigning the newly cloned chrome.app to a given desktop.

    The original Chrome app from the dock will allow it, but the freshly created app doesn't have the "Assign to" menu

    ReplyDelete