jakehilborn / displayplacer

macOS command line utility to configure multi-display resolutions and arrangements. Essentially XRandR for macOS.
MIT License
3.76k stars 133 forks source link

id switching #30

Open Sublevel4 opened 4 years ago

Sublevel4 commented 4 years ago

I got this installed and working via a shortcut app and via Automator. The issue I seem to be having is that the id is getting switched.

For example. I left my desk last night and everything was displaying correctly. When I came to my desk this morning. the monitors where switched. So I hit the shortcut. Screens flickered and stayed the same. I then tried the Automator app. Same result. I opened terminal and ran displayplacer list and got this

id:4927EFE8-6123-BA85-0FAD-1F365C7776E7 res:2560x1440 hz:60 color_depth:8 scaling:off origin:(0,0) degree:0" "id:6D890636-F5C6-E41E-FBC5-7DBE6EB37956 res:2560x1440 hz:60 color_depth:8 scaling:off origin:(-2560,0) degree:0

To fix it I swapped the ids and ran the Automator again within Automator and the displays where corrected. I had to swap the IDs two days ago in the same way. The persistent IDs shouldn't change, right? I have two 27" monitors, each plugged into separate Thunderbolt ports on a 2019 15" MBP

jakehilborn commented 4 years ago

Yeah that should not be happening. Are the two monitors the same brand and same model?

Sublevel4 commented 4 years ago

yes they are the exact same brand and model. I just came back to my desk after lunch and it was flipped again. the edits i made this morning didn't work so I swapped the IDs and ran it from Automator and it corrected. So being that its the same model displays seem like the os is swapping the IDs when it wakes up?

jakehilborn commented 4 years ago

I used to have 2 identical monitors. One at work in portrait mode, and one at home in landscape mode. macOS thought they were the same so I always had to change the orientation when plugging in my laptop.

Try this, use displayplacer list to get the contextual screen ids for each of your monitors. Use those screen ids instead of the persistent screen ids. As long as you plug your monitors into the same ports using the same cables you may have luck with the contextual ids not changing.

Sublevel4 commented 4 years ago

I will get that a shot. For now, I am not unplugging as I am not going anywhere LOL. I will let you know what I find. Thank you for the great fix to this problem!

Sublevel4 commented 4 years ago

After a few days and a couple of display swaps. The contextual screen ids don't make any difference. It looks like they switch as well. For the moment I have two Automator apps on my desktop. the second has the reversed IDs. So if encounter the monitor swap, I click on #1, if that doesn't fix it I click on #2 with the swapped IDs.

Sublevel4 commented 4 years ago

It doesn't seem like this has anything to do with the problem posted above, but today one of my displays persistent IDs changed.

jakehilborn commented 4 years ago

What models are your monitors?

Sublevel4 commented 4 years ago

Ther are both BenQ GW2765 monitors

Sublevel4 commented 4 years ago

I have attached a rough log for the last 3 weeks. I don't know if it might help track this down.

screen swap errors.txt

joshgolden commented 4 years ago

I'm having this same issue. Persistent IDs for two identical monitors are changing each time I plug them in. Not just swapping IDs, but actually changing to completely new IDs. As a result, displayplacer kicks back an "Unable to find screen..." error for both of them. Strangely, it works occasionally after several unplugs/replugs, suggesting that maybe the screens are cycling through a discrete number of IDs...?

I am connecting to the monitors via this "J5 Create" USB-C hub: https://en.j5create.com/collections/usb-type-c-hubs/products/jcd381

Would the hub potentially cause this issue?

Maybe I could log the IDs that I see after each replug, and try to determine if there's a pattern?

Thanks for all you've done on this app... when it works, it works like a charm!

yongming-qin commented 4 years ago

@joshgolden Same issue here. I tried SwitchResX today and saw the same problem. But I found the ID for one monitor is always the same (need to confirm this). The ID of the other monitor changes among two values (or cycles through some as mentioned). So I wrote a small python script to keep the non-changing ID there and use the other ID whatever appears. I'll use this script for a few days and report the result. display_arrange.py.txt

update 2020/06/04: Works well now. The ids do appear repeatedly. Now I just remember all the ids and if the id appears I use the corresponding displayplacer setting. Here is the current script for reference. display_arrange.py.txt

joshgolden commented 4 years ago

I determined that the monitors were each cycling between two unique IDs. So I updated my executable Terminal script to run displayplacer twice, separately for each set of IDs. Seems to be working so far. So that might be a simpler workaround for others experiencing the same issue... not quite as elegant as the Python script above, but gets the job done without any real programming skills required.

Sublevel4 commented 4 years ago

Yes, it seems that they swap two IDs and they are always the same, you just don't know which it is. Oddly I have created two Automator apps with the contextual IDs each has the IDs swapped. that seems to be working if my screens are swapped I click on the first one if that doesn't work I click on the second one. This week that has been working

phaedrusrex commented 4 years ago

Wanted to echo this experience. I have two identical monitors that keep flipping "persistent" IDs back and forth when my 2020 16" MBP goes to sleep. One point to note is that I had exactly the same setup (same Satechi dual HDMI adapter, USB hub, etc., I basically plugged the new laptop into the existing USB-C/Thunderbolt accessories) on my 2017 15" MBP and it was stable. Makes me wonder if it's the video card or some other change in the MBP that is contributing to this behaviour.

Is the issue that the drivers in MacOS don't make the effort to grab the serial number of the monitors or that the monitors lack a unique serial number?


------------------- MAIN EDID BLOCK -----------------

EDID Version........1.3
Manufacturer........LHC (3103)
Product ID..........12800 (3200)
Serial Number.......00000000

Manufactured........Week 34 of year 2019
Max H Size..........60 cm
Max V Size..........34 cm
Gamma...............2.20
luiscachog commented 4 years ago

Having a similar issue, but I'm connecting:

MacBook <-> USB Dock <-> 3 Identical Monitors (1 DisplayPort, 2 HDMIs)(BenQ 2780)

I've installed the DisplayLink driver to be able to use the Dock Graphic card. But even if I put the Mac on sleep mode and don't disconnect the dock when I wake it it's switching the monitors. I already tried both ID's:

Starts working after I run again: displayplacer list

And then, with the new ID's:

displayplacer "id:1952332166 res:1920x1080 hz:60 color_depth:4 scaling:off origin:(0,0) degree:0" "id:1952332165 res:1920x1080 hz:60 color_depth:4 scaling:off origin:(1920,0) degree:0" "id:1952332164 res:1920x1080 hz:60 color_depth:4 scaling:off origin:(-1920,0) degree:0"

bxm156 commented 4 years ago

Same issue here, I have two of the same Trio models from mobilepixels.us that use DisplayLink.

xdhmoore commented 4 years ago

I also have two identical monitors that seem to be swapping persistent ids with one another.

xdhmoore commented 4 years ago

I wrote my own script. I have 2 external and 1 laptop monitor, so this script tries to detect which are the 2 external monitors and then just switches the configuration for them using displayplacer:

https://gist.github.com/xdhmoore/cb8321bbd00f2fe07e418d9fa93367ca

markdon commented 4 years ago

I came to post my bodgy script that has been working well for the past several weeks: https://gist.github.com/markdon/6d13190d4518f16e61c104a1fbe1606d

@xdhmoore 's script seems way better! It doesn't hardcode anything and just swaps the two external displays between their existing configs. So you would run a script that you expect to place your monitors correctly, then run ./toggle-displays.bash if they are in the wrong positions.

yuliswe commented 2 years ago

I arrived here by googling a Macbook issue where when you connect 2 external displays via a dock, the displays swap randomly when the MacBook wakes up.

@MarcH 's answer in this post explains that it is a macOS issue: https://apple.stackexchange.com/questions/42835/primary-display-randomly-changes

I am using this tool as a workaround, by programmatically swapping the monitors' positions. Unless there's a way to grep the factory serial numbers of the monitors, there's no way to fix the identification problem.

Oliver-Saer commented 2 years ago

Having this issue as well, but interestingly only since today having upgraded my Intel Mac to an M1-based Mac.

Anyone using an Intel Mac and still having this issue?

markdon commented 2 years ago

@Oliver-Saer On MBP 2019 with two identical monitors on USB-C, one portrait. Actually for me, this problem has either stopped entirely or it's so infrequent that I forget when it last happened. I have stopped connecting to a different second desk with a dock and only use this one set of monitors, so that could have helped. They do get disconnected every day.

angel-langdon commented 2 years ago

This is an internal Apple API problem, monitors IDs keep switching randomly at wake up. I recommend using contextual ids instead of the persistent ids (because these switch randomly)

Steps

displayplacer list

Copy the output and replace id:<persistend-id> for id:<contextual-id>

In my case the final command would be ( I have replaced persistent-ids for contextual-ids)

displayplacer "id:5 res:1920x1080 hz:60 scaling:off origin:(0,0) degree:0" "id:2 res:1920x1080 hz:60 scaling:off origin:(-1920,0) degree:0" "id:4 res:1920x1080 hz:60 scaling:off origin:(1920,0) degree:0"

I am not 100% sure but I think there is a trade off with this method, that is, you have to connect each screen to a different port

LeoUfimtsev commented 2 years ago

Ran into the same problem. Mac Mini Intel. My use case is switch between LG Monitor and Samsung TV as main display and mirror the other in a scaled way. Ran into the changing ID problem. After some grumbling, I hacked together a functional bash script that dynamically identifiers IDs.

Setup:

I ended up hacking a little bash script that identifies ID based on some pattern in displayplacer list command. (I found that the size is 80/85 for TV and 37/29 for monitor depending on which one is primary). I then read the lines before and 4th column.

I then run those bash functions when I want to switch between monitor and TV. I have them tied to hotkeys via Better Touch tools. Works well. Would be nice to have fixed in future or maybe have a mechanism to set based on some alternative identification method that takes into account that ID might change.

l.sam () {
samsung=$(/usr/local/bin/displayplacer list | grep -B 2 "80 inch\|85 inch" | grep "Persi" | cut -f4 -d " ")
echo "Identified 80 inch or 85 inch screen as: $samsung"
lg=$(/usr/local/bin/displayplacer list | grep -B 2 "29 inch\|37 inch" | grep "Persi" | cut -f4 -d " ")
echo "Identified 29 or 37 inch as: $lg"
/usr/local/bin/displayplacer "id:${samsung}+${lg} res:1920x1080 hz:60 color_depth:8 scaling:on origin:(0,0) degree:0"
}

l.lg () {
samsung=$(/usr/local/bin/displayplacer list | grep -B 2 "80 inch\|85 inch" | grep "Persi" | cut -f4 -d " ")
echo "Identified 80 inch or 85 inch screen as: $samsung"
lg=$(/usr/local/bin/displayplacer list | grep -B 2 "29 inch\|37 inch" | grep "Persi" | cut -f4 -d " ")
echo "Identified 29 or 37 inch as: $lg"
/usr/local/bin/displayplacer "id:${lg}+${samsung} res:3200x1333 hz:75 color_depth:8 scaling:on origin:(0,0) degree:0"
}
jakehilborn commented 1 year ago

@Sublevel4 @joshgolden @yongming-qin @phaedrusrex @luiscachog @bxm156 @xdhmoore @markdon @yuliswe @Oliver-Saer @angel-langdon @LeoUfimtsev displayplacer v1.4.0 supports addressing screens by serial id. If all of the screens in your setup have unique serial ids, this should fix the id switching issue.

Could you try out the new version and let me know if it works on your setup?

xdhmoore commented 1 year ago

@jakehilborn Unfortunately I no longer have the hardware to reproduce this issue.

Oliver-Saer commented 1 year ago

I'm no longer using this as toggling off Apple > System Preferences > Mission Control > Automatically rearrange spaces has stopped my displays from changing positions between sessions, therefore alleviating my need for this tool.

yuliswe commented 1 year ago

@jakehilborn Last time I checked apples public API, I remember the unique serial ID was either always an empty string or just unavailable. What's changed?

Sublevel4 commented 1 year ago

@jakehilborn I updated today. When i run displayplacer list, both of the monitors are listed like this

Display 1 Persistent screen id: 4927EFE8-6123-BA85-0FAD-1F365C7776E7 Contextual screen id: 1952342476 Serial screen id: s21573

Display 2 Persistent screen id: 6D890636-F5C6-E41E-FBC5-7DBE6EB37956 Contextual screen id: 1952342475 Serial screen id: s21573

So for me the serial Ids are the same for both monitors. And for the record Oliver's Automatically rearrange spaces setting doesn't work for me, it still flips.

yuliswe commented 1 year ago

I'm on MBP M1 2012, macOS 13.4.1 (c) (22F770820d). I think they might have fixed the monitor flipping bug. It hadn't occurred to me in a few months.