As the old post “Setup default browser per Insync account” (Setup default browser per insync account) has been closed, I am proposing a solution to manage multiple browser profiles.
My use case involves different .desktop
launchers for Google Chrome, each with a unique --user-data-dir
, which provides full separation between my Google accounts (for personal and work purposes).
I created an executable bash script to replace the “Insync Helper” command. I also created a .desktop
launcher named “My Insync Helper” to run the script and associated it with all Insync file types, such as .gddoc
, .gdslides
, etc.
The script accepts the path of an Insync file, extracts the cloud account and the cloud file URL, selects the correct launcher, and opens it using the gtk-launch
command.
Here is the script. You’ll need to configure the CLOUD_ACCOUNT_EMAIL_DESKTOP_EXEC_MAP
variable to match your accounts and respective launcher.
#!/bin/bash
# Example of an Insync file content (.gddoc, .gdsheet, .gdslides)
# {"url": "<cloud-url>", "file_id": "<file_id>", "account_email": "<cloud_account_email>"}
if [ ! -f "$1" ]; then
echo "File not found [$1]"
exit 1
fi
CLOUD_ACCOUNT_EMAIL=$(cat "$1" | tr { '\n' | tr , '\n' | tr } '\n' | grep ".account_email" | awk -F'"' '{print $4}')
CLOUD_URL=$(cat "$1" | tr { '\n' | tr , '\n' | tr } '\n' | grep ".url" | awk -F'"' '{print $4}')
if [[ "$CLOUD_ACCOUNT_EMAIL" == "" ]]; then
echo "Cloud account email not present"
exit 1
fi
if [[ "$CLOUD_URL" == "" ]]; then
echo "Cloud URL not present"
exit 1
fi
DEFAULT_DESKTOP_EXEC="google-chrome"
# Each line must have the following format
# <cloud-account-email>:<app-exec-name>
#
# <cloud-account-email> must match the content of the filed "account_email" in the Insync file
# <app-exec-name> is the .desktop file name without .desktop suffix
# Eg. for file "google-chrome-my-profile.desktop
# the <app-exec-name> must be "google-chrome-my-profile"
CLOUD_ACCOUNT_EMAIL_DESKTOP_EXEC_MAP="
account1@google.com:google-chrome-profile1
account2@example.net:google-chrome-profile2
account3@whatever.org:google-chrome-profile3
"
if [[ $CLOUD_ACCOUNT_EMAIL ]]; then
DESKTOP_EXEC=$(echo "$CLOUD_ACCOUNT_EMAIL_DESKTOP_EXEC_MAP" | grep "$CLOUD_ACCOUNT_EMAIL" | cut -d ":" -f2)
fi
if [[ -z $DESKTOP_EXEC ]]; then
DESKTOP_EXEC=$DEFAULT_DESKTOP_EXEC
fi
echo "gtk-launch $DESKTOP_EXEC $CLOUD_URL"
gtk-launch $DESKTOP_EXEC "$CLOUD_URL"