Opening chrome windows with shortcut keys

Hi, I'm new to Mac and everyone recommended using Bettertouchtool. I have a very specific question. Tried doing it myself and wasn't sure how to.

If I have multiple chrome profiles: how can I create a shortcut to open a new window for each profile?

For example;
Profile 1: CTRL+A should open a new window
Profile 2: CTRL+S should...
Profile 3: CTRL+D should...
and so on.

Is that possible to do? Coming from a Windows laptop that had a great dock that allowed me to pin multiple chrome profiles in the dock. Apple laptops don't allow that.

You can use a shellscript action and call "open -na 'Google Chrome' --args --profile-directory=profile_name"

This reminds me of a BTT workflow I created a while back. I'll share it with you, @Busy_Living as it may provide you with some inspiration.

Triggered by a keyboard shortcut, this script toggles the current Chrome tab between profiles. It reopens the same page in the other profile and closes the original, so you can switch accounts/cookies with a single keystroke.

#!/bin/bash

# Function to log debug information
log_debug() {
    echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" >> /tmp/btt_chrome_switcher_v2.log
}

# Start timing
start_time=$(date +%s)
log_debug "Start debugging..."

# Set PATH
PATH="/Applications/iMazing.app/Contents/MacOS/:$HOME/.nvm/versions/node/v20.15.0/bin:/opt/homebrew/opt/postgresql@15/bin:/opt/homebrew/opt/libxslt/bin:$HOME/.gem/ruby/3.2.0/bin:$HOME/.rubies/ruby-3.2.0/lib/ruby/gems/3.2.0/bin:$HOME/.rubies/ruby-3.2.0/bin:$HOME/go/bin:$HOME/.cargo/bin:/opt/homebrew/sbin:$HOME/google-cloud-sdk/bin:/opt/homebrew/bin:$HOME/miniconda3/bin:$HOME/miniconda3/condabin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/opt/X11/bin:/Library/Apple/usr/bin:$HOME/.local/bin:$HOME/.cache/lm-studio/bin:/Applications/Little Snitch.app/Contents/Components/:$PATH"

# Get current tab info
current_tab_info=$(OUTPUT_FORMAT="json" chrome-cli info | jq -r '{id: .id, url: .url}')
current_tab_id=$(echo "$current_tab_info" | jq -r '.id')
url=$(echo "$current_tab_info" | jq -r '.url')

log_debug "Parsed tab ID: $current_tab_id"
log_debug "Parsed URL: $url"

# Get email of current Chrome window profile
email=$(osascript -e 'tell application "System Events" to tell process "Google Chrome" to get the name of the front window' | awk -F' - ' '{print $NF}' | sed -E 's/.*\((.*)\).*/\1/' | tr '[:upper:]' '[:lower:]')

log_debug "Fetched Email: $email"

# Generate profile mapping
profile_mapping=$(eza "$HOME/Library/Application Support/Google/Chrome/" -D --absolute --no-quotes | grep "Profile " | \
while read -r profile; do
    email_in_profile=$(cat "$profile/Preferences" | jq -r '.account_info[0].email' 2>/dev/null)
    profile_name=$(basename "$profile")
    if [ "$email_in_profile" != "null" ] && [ -n "$email_in_profile" ]; then
        echo "\"$email_in_profile\": \"$profile_name\","
    fi
done | sed '$ s/,$//' | awk 'BEGIN {print "{"} {print} END {print "}"}')

log_debug "Profile Mapping: $profile_mapping"

# Find the profile corresponding to the email
active_profile=$(echo "$profile_mapping" | jq -r --arg email "$email" '.[$email]')

if [ -z "$active_profile" ]; then
    log_debug "No active profile found for the email: $email"
    dialog --title "Error: Profile Not Found" --message "No active profile found for email: $email. Please check your Chrome profiles." --style caution
    exit 1
fi

log_debug "Active Profile: $active_profile"

# Switch logic for profile management
# I want to switch between Profile 1 and 17
case "$active_profile" in
    "Profile 1")
        profile_to_switch_to="Profile\ 17"
        ;;
    "Profile 17")
        profile_to_switch_to="Profile\ 1"
        ;;
    *)
        profile_to_switch_to="$active_profile"
        ;;
esac

log_debug "Profile to Switch To: $profile_to_switch_to"

# If no profile switch is needed, exit early
if [ -z "$profile_to_switch_to" ]; then
    log_debug "No profile switch required."
    exit 0
fi

# Open the URL in Google Chrome with the specified profile
open_tab_cmd="/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome \"$url\" --profile-directory=$profile_to_switch_to"
log_debug "Final command to open new tab: $open_tab_cmd"
eval "$open_tab_cmd"

# Close the original tab
close_tab_cmd="chrome-cli close -t $current_tab_id"
log_debug "Final command to close original tab: $close_tab_cmd"
eval "$close_tab_cmd"

# Calculate and log execution time
end_time=$(date +%s)
execution_time=$((end_time - start_time))
log_debug "Profile switch and tab close attempt completed."
log_debug "Script execution time: ${execution_time}s"

exit 0