Created
November 19, 2024 17:56
-
-
Save mtao/0553b55a9b3fe06bafe676b658652d14 to your computer and use it in GitHub Desktop.
Script for validating that I did plug my framework into my office setup and reordering the screens if so
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 | |
| # I have 3 monitors at the office (including my framework's display). This | |
| # script makes sure they're plugged in and then reorders them properly | |
| # gets output info from sway | |
| output_data=$( swaymsg -t get_outputs ) | |
| # for convenience simplify the output - and select the first mode available | |
| output_data=$( echo $output_data | jq ".[] | | |
| [{id:.id,name:.name,mode:.modes[0],make:.make,model:.model}]" ) | |
| # extract the properties of each particular monitor | |
| center=$( echo $output_data | jq '.[] | | |
| select( .make=="LG Electronics" and .model=="LG HDR 4K")' ) | |
| left=$( echo $output_data | jq '.[] | | |
| select( .make=="Dell Inc." and .model=="DELL P2722H")' ) | |
| right=$( echo $output_data | jq '.[] | | |
| select( .make=="BOE" and .model=="0x095F")' ) | |
| # make sure all 3 monitors were selected | |
| if [[ -z "$center" || -z "$left" || -z "$right" ]] | |
| then | |
| echo "Missing a monitor for office use, I see: " | |
| echo "$center $left $right" | jq -r '"Make: \(.make); Model: \(.model)"' | |
| exit 1 | |
| fi | |
| # each time a monitor is positioned we use its size to update the x_pos | |
| x_pos=0 | |
| # read the name | |
| left_output=$( echo $left | jq '.name' ) | |
| # configure position of that output using the target position | |
| swaymsg output $left_output pos $x_pos 0 | |
| # update x_pos | |
| left_x_size=$( echo $left | jq '.mode.width' ) | |
| x_pos=$( expr $left_x_pos + $left_x_size ) | |
| center_output=$( echo $center | jq '.name' ) | |
| swaymsg output $center_output pos $x_pos 0 | |
| center_x_size=$( echo $center | jq '.mode.width' ) | |
| x_pos=$( expr $x_pos + $center_x_size ) | |
| right_output=$( echo $right | jq '.name' ) | |
| swaymsg output $right_output pos $x_pos 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment