Forked from prasadsilva/fresh-chrome-with-custom-tz.sh
Last active
February 20, 2017 14:27
-
-
Save d42ohpaz/e046aeff3ed5959f973bbb2d0bae1175 to your computer and use it in GitHub Desktop.
Launch new instances of Google Chrome on OS X with isolated cache, cookies, user config and custom Timezone
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# The MIT License (MIT) | |
# | |
# Copyright (c) 2013 Stuart Sierra | |
# | |
# Permission is hereby granted, free of charge, to any person | |
# obtaining a copy of this software and associated documentation files | |
# (the "Software"), to deal in the Software without restriction, | |
# including without limitation the rights to use, copy, modify, merge, | |
# publish, distribute, sublicense, and/or sell copies of the Software, | |
# and to permit persons to whom the Software is furnished to do so, | |
# subject to the following conditions: | |
# | |
# The above copyright notice and this permission notice shall be | |
# included in all copies or substantial portions of the Software. | |
# | |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | |
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | |
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | |
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
# SOFTWARE. | |
# Original version: https://gist.github.com/prasadsilva/225fd0394a51e52bf62f | |
# This version: https://gist.github.com/dohpaz42/e046aeff3ed5959f973bbb2d0bae1175 | |
# fresh-chrome | |
# | |
# Use this script on OS X to launch a new instance of Google Chrome | |
# with its own empty cache, cookies, and user configuration. | |
# | |
# The first time you run this script, it will launch a new Google | |
# Chrome instance with a permanent user-data directory, which you can | |
# customize below. Perform any initial setup you want to keep on every | |
# new Chrome instance, such as adding bookmarks and extensions. Then | |
# quit this Chrome instance with Command-Q or by selecting "Quit" from | |
# the "Chrome" menu. (The red "close" button is not sufficient.) | |
# | |
# AFTER that, every time you run this script it will launch a new | |
# Google Chrome instance with a temporary user-data directory copied | |
# from the one you set up the first time you ran this script. Every | |
# new instance of Google Chrome launched by this script will be | |
# completely isolated from the others. | |
# Permanent directory to store the user-data directory of your 'fresh' | |
# Chrome configuration. | |
fresh_dir="$HOME/.fresh-chrome" | |
### Main script begins | |
BASENAME=$(basename $0) | |
DEFAULT_TZ="America/Los_Angeles" | |
app_name="Google Chrome" | |
app_path=`defaults read com.google.chrome LastRunAppBundlePath 2>/dev/null` | |
if [ "x$app_path" = "x" ]; then | |
app_path="/Applications/${app_name}.app" | |
fi | |
bin_name=`defaults read "${app_path}/Contents/Info.plist" CFBundleExecutable 2>/dev/null` | |
if [ "x$bin_name" = "x" ]; then | |
echo "$BASENAME: Missing application \"$app_name\" not installed or misconfigured" | |
exit 1 | |
fi | |
bin_path="${app_path}/Contents/MacOS/${bin_name}" | |
if [ "x$1" = "x" ]; then | |
export TZ=$DEFAULT_TZ | |
elif [ ! -f "/usr/share/zoneinfo/$1" ]; then | |
echo "$BASENAME: To get a list of valid timezones, run the following command:" | |
echo " sudo systemsetup -listtimezones" | |
exit 1 | |
else | |
export TZ="$1" | |
fi | |
# Cleanup after ourselves | |
function cleanup() { | |
if [ -d "$tmp_dir" ]; then | |
echo "$BASENAME: Cleaning up after ourselves..." | |
rm -rf "$tmp_dir" | |
fi | |
} | |
trap cleanup 0 1 2 3 15 | |
# Temporary directory in which to create new user-data directories for | |
# temporary Chrome instances. | |
tmp_dir=$(mktemp -d) | |
set -e | |
timestamp=`date +%Y%m%d%H%M%S` | |
echo "$BASENAME: Launching ${app_name} in time zone ${TZ}..." | |
if [[ -e "$fresh_dir" ]]; then | |
user_dir="$tmp_dir/chrome-$timestamp-$RANDOM" | |
cp -r "$fresh_dir" "$user_dir" | |
"${bin_path}" --user-data-dir="$user_dir" >/dev/null 2>&1 | |
else | |
"${bin_path}" --user-data-dir="$fresh_dir" >/dev/null 2>&1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment