Mac で 複数バージョン、複数プロファイルの Chrome を使う

基本的にはこちらのエントリに載っていることをやればいい。

ふたつ目のリンクにあるスクリプトはとても素晴らしい。やっぱりアイコンがないと寂しい。でも Chrome のパスがデフォルトと異なっていると、うまく動かなかった。ちょっとだけ修正して以下のようにした。CHROME_APP をコメントアウトして、Enter Chrome Path ってところを追加した。

#!/bin/sh

#
# Create Google Chrome launcher (for Mac)
#

# コメントアウトしちゃう
# CHROME_APP="/Applications/Google Chrome.app"
CHROME_PROFILE_DIR="$HOME/Library/Application Support/Google/Chrome"

echo "Enter profile name: \c"
read PROFILE_NAME
if [ "x$PROFILE_NAME" == "x" ]; then
	echo "Error: profile name is empty"
	exit
fi

# Chrome のパスも入力してもらう
echo "Enter Chrome Path [/Applications/Google Chrome.app]: \c"
read CHROME_APP
if [ "x$CHROME_APP" == "x" ]; then
        CHROME_APP="/Applications/Google Chrome.app"
fi

echo "Enter launcher name [Google Chrome ($PROFILE_NAME)]: \c"
read LAUNCHER_NAME
if [ "x$LAUNCHER_NAME" == "x" ]; then
	LAUNCHER_NAME="Google Chrome ($PROFILE_NAME)"
fi

echo "Enter boot options []: \c"
read OPTIONS

echo "Enter dist dir [.]: \c"
read DIST_DIR
if [ "x$DIST_DIR" == "x" ]; then
	DIST_DIR="."
fi

USER_DATA_DIR="$CHROME_PROFILE_DIR/$PROFILE_NAME"
CONTENTS_DIR="$DIST_DIR/$LAUNCHER_NAME.app/Contents"

if [ ! -e "$CHROME_APP" ]; then
	echo "Google Chrome is not installed"
	exit
fi

if [ -e "$USER_DATA_DIR" ]; then
	echo "Profile exists"
else
	echo "Create profile at $USER_DATA_DIR"
	mkdir -p "$USER_DATA_DIR"
fi

if [ -e "$CONTENTS_DIR" ]; then
	echo "Launcher exists"
	exit
fi

echo "Create launcher at $DIST_DIR/$LAUNCHER_NAME.app"
mkdir -p "$CONTENTS_DIR"
mkdir "$CONTENTS_DIR/MacOS"
mkdir "$CONTENTS_DIR/Resources"

echo "Copy resources from Google Chrome"
cp "$CHROME_APP/Contents/Resources/app.icns" "$CONTENTS_DIR/Resources"

echo "Write Info.plist"
cat <<EOD > "$CONTENTS_DIR/Info.plist"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>CFBundleIconFile</key>
	<string>app.icns</string>
</dict>
</plist>
EOD

echo "Write executable"
cat << EOD > "$CONTENTS_DIR/MacOS/$LAUNCHER_NAME"
#!/bin/sh

"$CHROME_APP/Contents/MacOS/Google Chrome" $OPTIONS --user-data-dir="$USER_DATA_DIR" &
EOD
chmod +x "$CONTENTS_DIR/MacOS/$LAUNCHER_NAME"

echo "Done"

元のスクリプトはこちら。https://gist.github.com/882672


こんな感じになった。canary はもともとプロファイルが他と分かれているのでそのままにしている。こんな感じになった。

/Applications/Chromes
├ stable
│ ├ Google Chrome.app
│ └ Google Chrome (stable).app
├ beta
│ ├ Google Chrome.app
│ └ Google Chrome (beta).app
├ dev
│ ├ Google Chrome.app
│ └ Google Chrome (dev).app
└ canary
    └ Google Chrome Canary.app

Chrome は stable と dev を使っていたけど、beta と canary もいれた。
Chrome dev をメインに使っていたけど、最近起動してすぐにクラッシュしてしまうようになった。困った。Chrome を置き換えて、プロファイルを切り替えるとちゃんと起動した。twitter で beta だと問題ないと教えてもらって、ついでに全部いれて、プロファイルもきれいに分けてみた。
いい感じ。ちなみに dev のプロファイルは beta でも使えて、stableでは使えないみたい。