Created
August 27, 2024 14:52
-
-
Save djsegal/fef7237eedc24e109e1af83014138ad5 to your computer and use it in GitHub Desktop.
Swap two identical dimension displays on MacOS using displayplacer and cliclick brew packages
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 | |
# Path to displayplacer and cliclick | |
DISPLAYPLACER="/opt/homebrew/bin/displayplacer" | |
CLICLICK="/opt/homebrew/bin/cliclick" | |
# Get current mouse position using cliclick | |
current_position=$($CLICLICK p | awk -F, '{print $1, $2}') | |
current_x=$(echo $current_position | awk '{print $1}') | |
current_y=$(echo $current_position | awk '{print $2}') | |
# Define monitor width | |
monitor_width=1920 | |
# Perform the display swap | |
$DISPLAYPLACER list | tail -n1 | sed 's/displayplacer //;s/id:\(.\{36\}\) res:\([0-9x]\{7,9\}\) \(.*\)id:\(.\{36\}\) res:\2/id:\4 res:\2 \3id:\1 res:\2/g' | xargs $DISPLAYPLACER | |
# Calculate new mouse position with phase shift | |
new_x=$(( (current_x + monitor_width) % (2 * monitor_width) )) | |
new_y=$current_y | |
# Move the mouse to the new position | |
$CLICLICK m:$new_x,$new_y |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment