#!/bin/bash URL="https://example.com" # <-- REPLACE with the real Scolia site URL before running CHROME_PROFILE="$HOME/.browser-profiles/chrome-scolia" FIREFOX_PROFILE="$HOME/.browser-profiles/firefox-scolia" mkdir -p "$CHROME_PROFILE" # --- Detect connected monitors and their positions via xrandr (X11 only) --- # Example xrandr line: "HDMI-1 connected 1920x1080+0+0 ..." mapfile -t MONITORS < <(xrandr --query 2>/dev/null | grep " connected" | grep -oP '\d+x\d+\+\d+\+\d+') if [ "${#MONITORS[@]}" -lt 2 ]; then echo "Warning: fewer than 2 monitors detected (or not running X11). Both windows may open on the same screen." fi # Parse "WxH+X+Y" into width, height, x-offset, y-offset parse_geom() { local geom=$1 WIDTH=$(echo "$geom" | grep -oP '^\d+') HEIGHT=$(echo "$geom" | grep -oP '(?<=x)\d+') XOFF=$(echo "$geom" | grep -oP '(?<=\+)\d+(?=\+)') YOFF=$(echo "$geom" | grep -oP '(?<=\+)\d+$') } # --- Screen 1 -> Chrome --- if [ "${#MONITORS[@]}" -ge 1 ]; then parse_geom "${MONITORS[0]}" CHROME_X=$XOFF CHROME_Y=$YOFF else CHROME_X=0 CHROME_Y=0 fi google-chrome \ --user-data-dir="$CHROME_PROFILE" \ --new-window \ --window-position="$CHROME_X,$CHROME_Y" \ "$URL" & sleep 2 # give Chrome a moment before launching Firefox # --- Screen 2 -> Firefox --- if [ "${#MONITORS[@]}" -ge 2 ]; then parse_geom "${MONITORS[1]}" elif [ "${#MONITORS[@]}" -eq 1 ]; then parse_geom "${MONITORS[0]}" # fallback: same screen else XOFF=0 YOFF=0 fi FIREFOX_X=$XOFF FIREFOX_Y=$YOFF if [ ! -d "$FIREFOX_PROFILE" ]; then firefox -CreateProfile "scolia $FIREFOX_PROFILE" fi firefox -P "scolia" --new-instance --new-window "$URL" & sleep 2 # Firefox doesn't support --window-position as a launch flag reliably, # so we reposition it after launch using wmctrl (X11 only) if command -v wmctrl &> /dev/null; then wmctrl -r "Mozilla Firefox" -e 0,"$FIREFOX_X","$FIREFOX_Y",-1,-1 else echo "Tip: install 'wmctrl' (sudo apt install wmctrl) for automatic Firefox window positioning." fi