Skip to content

Instantly share code, notes, and snippets.

@gtirloni
Last active August 17, 2023 12:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gtirloni/9a409b1d2dd08f447f93168c32bd3393 to your computer and use it in GitHub Desktop.
Save gtirloni/9a409b1d2dd08f447f93168c32bd3393 to your computer and use it in GitHub Desktop.
Google Chrome work profiles on Linux

Work profile with Google Chrome on Linux (GNOME)

The goal is to open a different profile for work-related URLs opened anywhere on the desktop.

Install Steps

  1. Copy default-browser.sh to $HOME/bin (or somewhere else in your PATH)
  2. Copy default-browser.desktop to $HOME/.local/share/applications
  3. Update $HOME/.config/mimeapps.list with proper values (or create file from scratch)
  4. Go to Settings > Default Applications and configure "Default Browser" for Web

Application Configuration

To open a URL with the work profile, you just have to set the environment variable WORK=1 beforehand.

$ WORK=1 xdg-open https://google.com

You can add WORK=1 anywhere needed. For example, in a Flatpak's configuration so that Flatpak app always use the work profile. Use Flatseal to edit the environment variables.

[Desktop Entry]
Version=1.0
Name=Default Web Browser
GenericName=Web Browser
Comment=Access the Internet
Exec=/home/__YOUR_USERNAME_HERE__/bin/default-browser.sh %U
StartupNotify=false
Terminal=false
Icon=google-chrome
Type=Application
Categories=Network;WebBrowser;
MimeType=application/pdf;application/rdf+xml;application/rss+xml;application/xhtml+xml;application/xhtml_xml;application/xml;image/gif;image/jpeg;image/png;image/webp;text/html;text/xml;x-scheme-handler/http;x-scheme-handler/https;
Actions=new-window;new-private-window;
[Desktop Action new-window]
Name=New Window
Exec=/home/gtirloni/bin/default-browser.sh %U
[Desktop Action new-private-window]
Name=New Incognito Window
Exec=/home/gtirloni/bin/default-browser.sh %U --incognito
#!/bin/bash
PARENT_COMMAND=$(ps -o comm= $PPID)
WORK_PROFILE="Profile 1"
DEFAULT_PROFILE="Profile 2"
if [ -n "${WORK}" ] || [ "$PARENT_COMMAND" = "systemd" ]; then
google-chrome --profile-directory="${WORK_PROFILE}" "$@"
else
google-chrome --profile-directory="${DEFAULT_PROFILE}" "$@"
fi
[Default Applications]
text/html=default-browser.desktop
x-scheme-handler/http=default-browser.desktop
x-scheme-handler/https=default-browser.desktop
x-scheme-handler/about=default-browser.desktop
x-scheme-handler/unknown=default-browser.desktop
x-scheme-handler/mailto=default-browser.desktop
x-scheme-handler/webcal=default-browser.desktop
application/xhtml+xml=default-browser.desktop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment