Change Main Display via Keyboard Shortcut or command line in Mac OS X
Solution 1
hmscreens work great. Here's a sample command line to swap monitors:
hmscreens -setMainID `hmscreens -info | grep "Screen ID:" | head -2 | tail -1 | sed 's/[^0-9]*//g'`
Solution 2
The free terminal tool I wrote, displayplacer, allows you to configure the main display via scripts/hotkeys.
Configure your screens how you like, drag the "white bar" to your primary screen in the macOS system settings, and then execute displayplacer list
. It will output the command to run to put your screens in their current configuration. The screen with origin:(0,0)
is the main display with the "white bar". Run this terminal command through a script or bind to a hotkey using Automator/BetterTouchTool/etc.
This example makes the left screen the primary monitor. Execute a similar command whenever your machine randomly chooses the wrong primary display.
displayplacer "id:<leftScreenId> res:1920x1080 scaling:on origin:(0,0) degree:0" "id:<rightScreenId> res:1920x1080 scaling:on origin:(1920,0) degree:0"
Also available via Homebrew brew tap jakehilborn/jakehilborn && brew install displayplacer
Related videos on Youtube
PPR
Updated on September 18, 2022Comments
-
PPR over 1 year
I am using OS X 10.11.3 (15D21) with one monitor and one projector.
Mirroring is turned off.
Mac OS X has an option to switch the main display (the display that has the upper menu) via the System Preferences, as depicted in the attached screenshot:
Basically to switch one drags the little menu bar from one side to the other.
My question is: Is there a way to accomplish this switch via the keyboard or better yet as a command from the Terminal?
-
Simon Sheehan almost 8 yearsWhat is your goal? To have the dock on both screens?
-
PPR almost 8 yearsMy goal is to switch the "main" display (the one that has all the windows I've been working with).
-
linuxdev2013 almost 8 yearsWhat you want is to keybind that. look in the keyboard settings and under hotkeys select the display management app and set a keybinding to it and save.
-
-
Scott - Слава Україні about 5 yearsWhile your program may solve the OP’s problem, we prefer answers that explain how a piece of software can be used to achieve the desired effect.
-
Jake Hilborn almost 5 years@Scott I updated my answer to address your feedback.
-
Admin almost 2 yearsThe link does not seem to work. Redirects to the home page of that site's domain