Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oswaldo/cd4d83905d846322f317e2de91342bda to your computer and use it in GitHub Desktop.
Save oswaldo/cd4d83905d846322f317e2de91342bda to your computer and use it in GitHub Desktop.
Automatically setup external monitors
"""
Automatically setup external monitors 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
```
"""
import subprocess
if __name__ == '__main__':
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 origin:(0,0) degree:0" "id:{external_screen} res:2560x1440 scaling:on origin:(1729,0) 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