Last active
November 25, 2025 10:36
-
-
Save Stono/5ca1530b0e1b87fa0be0cb1eb91fe5ff to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #!/bin/bash | |
| set -e | |
| # Set Chrome user data directory | |
| CHROME_LOCATION="$HOME/Library/Application Support/Google/Chrome" | |
| # Gather profiles into arrays | |
| profile_dirs=() | |
| profile_labels=() | |
| for profile_dir in "$CHROME_LOCATION"/Default "$CHROME_LOCATION"/Profile* "$CHROME_LOCATION"/Guest*; do | |
| [ -d "$profile_dir" ] || continue | |
| pref_file="$profile_dir/Preferences" | |
| if [ -f "$pref_file" ]; then | |
| profile_name=$(grep -o '"name" *: *"[^\"]*"' "$pref_file" | head -1 | sed 's/.*: *"\([^\"]*\)"/\1/') | |
| account_email=$(grep -o '"email" *: *"[^\"]*"' "$pref_file" | head -1 | sed 's/.*: *"\([^\"]*\)"/\1/') | |
| if [ -z "$profile_name" ]; then | |
| profile_name="(no name found)" | |
| fi | |
| if [ -n "$account_email" ]; then | |
| label="$(basename "$profile_dir"): $profile_name ($account_email)" | |
| else | |
| label="$(basename "$profile_dir"): $profile_name" | |
| fi | |
| profile_dirs+=("$profile_dir") | |
| profile_labels+=("$label") | |
| fi | |
| done | |
| # Present options to user | |
| echo "Available Chrome profiles:" | |
| echo "" | |
| for i in "${!profile_labels[@]}"; do | |
| printf "%d) %s\n" "$((i+1))" "${profile_labels[$i]}" | |
| done | |
| echo "" | |
| # Prompt for source profile | |
| while true; do | |
| read -p "Enter the number of the profile you wish to copy FROM: " profile_idx | |
| if [[ "$profile_idx" =~ ^[0-9]+$ ]] && [ "$profile_idx" -ge 1 ] && [ "$profile_idx" -le "${#profile_dirs[@]}" ]; then | |
| profile_idx=$((profile_idx-1)) | |
| break | |
| else | |
| echo "Invalid selection. Please enter a valid number." | |
| fi | |
| done | |
| profile_dir="${profile_dirs[$profile_idx]}" | |
| profile_label="${profile_labels[$profile_idx]}" | |
| # Prompt for destination profile up front and confirm choices | |
| dst_profile="" | |
| dst_label="" | |
| while true; do | |
| read -p "Enter the number of the profile you wish to copy TO: " dst_idx | |
| if [[ "$dst_idx" =~ ^[0-9]+$ ]] && [ "$dst_idx" -ge 1 ] && [ "$dst_idx" -le "${#profile_dirs[@]}" ] && [ "$dst_idx" -ne "$((profile_idx+1))" ]; then | |
| dst_idx=$((dst_idx-1)) | |
| dst_profile="${profile_dirs[$dst_idx]}" | |
| dst_label="${profile_labels[$dst_idx]}" | |
| echo "" | |
| echo "Source profile: $profile_label" | |
| echo "Destination profile: $dst_label" | |
| while true; do | |
| read -p "Proceed with these selections? (y/n): " confirm_profiles | |
| if [[ "$confirm_profiles" =~ ^[Yy]$ ]]; then | |
| confirm_ok="yes" | |
| break | |
| elif [[ "$confirm_profiles" =~ ^[Nn]$ ]]; then | |
| echo "Okay, let's choose the destination profile again." | |
| confirm_ok="no" | |
| break | |
| else | |
| echo "Please answer y or n." | |
| fi | |
| done | |
| [ "$confirm_ok" = "yes" ] && break | |
| else | |
| echo "Invalid selection. Please enter a valid number (and not the same as source)." | |
| fi | |
| done | |
| # Prompt to copy bookmarks if Bookmarks file exists | |
| bookmarks_file="$profile_dir/Bookmarks" | |
| if [ -f "$bookmarks_file" ]; then | |
| echo "\nPreview of top 10 bookmarks in selected profile:" | |
| grep -o '"name" *: *"[^\"]*"' "$bookmarks_file" | sed 's/.*: *"\([^\"]*\)"/\1/' | head -10 | nl | |
| echo "" | |
| read -p "Do you want to copy bookmarks from this profile? (y/n): " copy_bm | |
| if [[ "$copy_bm" =~ ^[Yy]$ ]]; then | |
| dst_bookmarks="$dst_profile/Bookmarks" | |
| if [ -f "$dst_bookmarks" ]; then | |
| echo "Backing up destination Bookmarks file to $dst_bookmarks.bak" | |
| cp -f "$dst_bookmarks" "$dst_bookmarks.bak" | |
| fi | |
| cp -f "$bookmarks_file" "$dst_bookmarks" | |
| echo "Copied Bookmarks from $(basename "$profile_dir") to $(basename "$dst_profile")" | |
| else | |
| echo "Skipped copying bookmarks." | |
| fi | |
| else | |
| echo "No Bookmarks file found in selected profile." | |
| fi | |
| # Prompt to copy passwords if Login Data file exists | |
| login_data_file="$profile_dir/Login Data" | |
| if [ -f "$login_data_file" ]; then | |
| echo "" | |
| echo "A 'Login Data' file (passwords) was found in the selected profile." | |
| read -p "Do you want to copy passwords from this profile? (y/n): " copy_pw | |
| if [[ "$copy_pw" =~ ^[Yy]$ ]]; then | |
| dst_login_data="$dst_profile/Login Data" | |
| if [ -f "$dst_login_data" ]; then | |
| echo "Backing up destination Login Data file to $dst_login_data.bak" | |
| cp -f "$dst_login_data" "$dst_login_data.bak" | |
| fi | |
| cp -f "$login_data_file" "$dst_login_data" | |
| echo "Copied Login Data (passwords) from $(basename "$profile_dir") to $(basename "$dst_profile")" | |
| else | |
| echo "Skipped copying passwords." | |
| fi | |
| else | |
| echo "No 'Login Data' file found in selected profile." | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment