Last active
August 3, 2023 12:27
-
-
Save debsankha/7b4d0bbf1b9691245717c30f12a4bcd3 to your computer and use it in GitHub Desktop.
Automatically setup external monitors
This file contains 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
""" | |
Automatically setup external monitors at MOIA so that it's to the right of the | |
internal screen | |
Prerequisite: [displayplacer](https://github.com/jakehilborn/displayplacer) | |
```bash | |
brew tap jakehilborn/jakehilborn && brew install displayplacer | |
``` | |
Usage | |
----- | |
python autosetup_external_monitor.py above | |
python autosetup_external_monitor.py right | |
""" | |
import subprocess | |
import sys | |
if __name__ == "__main__": | |
if len(sys.argv) > 1 and sys.argv[1] == "above": | |
location_external_monitor = (0, -1118) | |
else: # assume to the right | |
location_external_monitor = (1729, 0) | |
internal_screen = subprocess.run( | |
"""displayplacer list | grep -B 2 "MacBook built in screen" | grep "Persistent screen id" | awk -F": " '{print $NF}'""", | |
shell=True, | |
capture_output=True, | |
text=True, | |
).stdout.strip() | |
external_screen = subprocess.run( | |
"""displayplacer list | grep -B 2 "27 inch external" | grep "Persistent screen id" | awk -F": " '{print $NF}'""", | |
shell=True, | |
capture_output=True, | |
text=True, | |
).stdout.strip() | |
displayplacer_command = f"""displayplacer "id:{internal_screen} res:1728x1117 scaling:on"""\ | |
f"""origin:(0,0) degree:0" "id:{external_screen} res:2560x1440 scaling:on origin:"""\ | |
f"""({location_external_monitor[0]},{location_external_monitor[1]}) degree:0" """ | |
subprocess.run( | |
displayplacer_command, shell=True, capture_output=True, text=True, check=True | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment