Last active
May 13, 2026 20:33
-
-
Save TeddybearCrisis/231f3306e0c19c1c45272997934997c9 to your computer and use it in GitHub Desktop.
Pop! OS set panel display
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 | |
| # Enforce cosmic panel (and dock) to show on a display given by a serial no. | |
| # Wayland and Cosmic Desktop only. Can be used in your bash ~/.profile. | |
| # Use 'cosmic-randr list --kdl' to find the serial no of connected displays. | |
| # | |
| # Usages: | |
| # ./set_panel_display.sh PRJM6HA014778 | |
| # ./set_panel_display.sh | |
| # parameters ------------------------------------------------------------------- | |
| SERIAL="PRJM6HA014850" # set a default display serial no. | |
| if [ ! -z "$1" ]; then SERIAL=$1; fi # ... from CLI param | |
| # read display config ---------------------------------------------------------- | |
| # read and reduce display config to relevant properties | |
| DISP_CFG=$(cosmic-randr list --kdl | grep "output\|serial\|{\|}") | |
| DISP_CFG=$(echo "$DISP_CFG" | tr '\n' ' ' | tr -s ' ' | sed 's/} } /} }\n/g') | |
| DISP_CFG=${DISP_CFG//"output \""/} | |
| DISP_CFG=${DISP_CFG//"\" enabled=#false"/} | |
| DISP_CFG=${DISP_CFG//"\" enabled=#true"/} | |
| DISP_CFG=${DISP_CFG//" modes { }"/} | |
| # filter for serial number | |
| SERIAL_CFG=$(echo "$DISP_CFG" | grep "$SERIAL") | |
| if [ -z "$SERIAL_CFG" ]; then | |
| echo -e "ERROR: No display found with serial: '$SERIAL'\n" | |
| echo -e "Available displays:\n$DISP_CFG" | |
| exit 1; | |
| fi | |
| set -e | |
| DISPLAY=$(echo "$SERIAL_CFG" | sed -r 's/(\S*).*/\1/g') | |
| # write cosmic configs --------------------------------------------------------- | |
| # write to cosmic config files | |
| CONFIG_ROOT="$HOME/.config/cosmic/com.system76.CosmicPanel" | |
| PANEL_CFG="$CONFIG_ROOT.Panel/v1/output" | |
| DOCK_CFG="$CONFIG_ROOT.Dock/v1/output" | |
| CONTENT="Name(\"$DISPLAY\")" | |
| echo $CONTENT | tee $DOCK_CFG $PANEL_CFG >/dev/null; | |
| echo "Serial '$SERIAL' -> $CONTENT set as panel and dock output config" | |
| # restart panel and dock ------------------------------------------------------- | |
| # although cosmic-comp checks for config changes it didn't always work. Hence: | |
| if pgrep cosmic-panel > /dev/null; then killall -9 cosmic-panel; fi | |
| # give systemd a chance to restart cosmic-panel before doing it manually | |
| sleep 2 | |
| if ! pgrep cosmic-panel > /dev/null; then | |
| cosmic-panel & | |
| disown | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment