Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Screen rotation #13

Open
jvarn opened this issue Nov 6, 2024 · 3 comments
Open

Screen rotation #13

jvarn opened this issue Nov 6, 2024 · 3 comments

Comments

@jvarn
Copy link

jvarn commented Nov 6, 2024

Is there any way to get 90°/270° screen rotation to work without having to force a logout (via script or ssh)?

@balopez83
Copy link
Owner

@jvarn No I don't believe there is a way. There is an app that might be able to do it. I think it's better display or something but it's paid. It allows you to set custom resolutions but don't know if it can rotate.

The built in rotation sensor won't ever work for macOS so without that it's difficult to rotate.

@jvarn
Copy link
Author

jvarn commented Nov 6, 2024

While auto rotation won't work, it is possible to rotate the screen by clicking on Display Settings in Control Center while holding down Alt/Option in order for the Rotation option to appear. However, only 180 and 0 (Standard) apply directly consistently; if 90 or 270 are selected, sometimes the screen rotates, but other tines the screen goes black. I haven't managed to identify a pattern of when it will work and when not. When it does goes black, if I am using Remote Desktop, I can see that the screen is still responsive to touch and clicks on the device (the mouse pointer moves on the remotely viewed display, but neither Finder nor any apps are responsive. Likewise, it is still responsive via secure shell. I read online somewhere that if you then switch the computer off and then on again, the screen will be rotated on the next boot. This is correct, but seemed unnecessary, so I tried simply clicking on 90 or 270, and then forcing a logout over ssh using sudo killall -HUP loginwindow. This took me to a 90/270 degree rotated login screen without needing a hard reboot.

So with a bit of experimentation, I put together an AppleScript that uses the Homebrew formula displayplacer to rotate the screen, added the script to an Automator Quick Action, and then assigned keyboard shortcuts (I used Cmd-Opt-9 for 90 degrees, Cmd-Opt-0 for 0 degrees, Cmd-Opt-8 for 180 degrees, and Cmd-Opt-7 for 270 degrees) via System Preferences.

Here's the script, in case anyone would like to use it or indeed improve it:

do shell script "/bin/bash -c '
export PATH=\"/usr/local/bin:$PATH\"

MONITOR=$(/usr/local/bin/displayplacer list | grep -o \"id:[^ ]*\" | grep -v \"id:$\" | head -n1 | cut -d\":\" -f2)
RES=1824x2736
HZ=60
DEGREE=90

/usr/local/bin/displayplacer \"id:$MONITOR res:$RES degree:$DEGREE\"
'"

And for 270:

do shell script "/bin/bash -c '
export PATH=\"/usr/local/bin:$PATH\"

MONITOR=$(/usr/local/bin/displayplacer list | grep -o \"id:[^ ]*\" | grep -v \"id:$\" | head -n1 | cut -d\":\" -f2)
RES=1824x2736
HZ=60
DEGREE=270

/usr/local/bin/displayplacer \"id:$MONITOR res:$RES degree:$DEGREE\"
'"

For 180:

do shell script "/bin/bash -c '
export PATH=\"/usr/local/bin:$PATH\"

MONITOR=$(/usr/local/bin/displayplacer list | grep -o \"id:[^ ]*\" | grep -v \"id:$\" | head -n1 | cut -d\":\" -f2)
RES=1368x912
HZ=60
DEGREE=180

/usr/local/bin/displayplacer \"id:$MONITOR res:$RES degree:$DEGREE\"
'"

For 0:

do shell script "/bin/bash -c '
export PATH=\"/usr/local/bin:$PATH\"

MONITOR=$(/usr/local/bin/displayplacer list | grep -o \"id:[^ ]*\" | grep -v \"id:$\" | head -n1 | cut -d\":\" -f2)
RES=1368x912
HZ=60
DEGREE=0

/usr/local/bin/displayplacer \"id:$MONITOR res:$RES degree:$DEGREE\"
'"

For those times when it starts giving me a black screen, I've been experimenting with this approach to force a logout after rotating the screen:

display dialog "This will rotate your screen and log you out. Do you want to proceed?" buttons {"Cancel", "Proceed"} default button "Proceed"
if the button returned of the result is "Proceed" then
    set rotationScript to "#!/bin/bash
export PATH=\"/usr/local/bin:$PATH\"

MONITOR=$(/usr/local/bin/displayplacer list | grep -o 'id:[^ ]*' | grep -v 'id:$' | head -n1 | cut -d':' -f2)
RES=$(/usr/local/bin/displayplacer list | grep -m1 -o 'res:[0-9]*x[0-9]*' | cut -d':' -f2)

if [ -n \"$MONITOR\" ] && [ -n \"$RES\" ]; then
    /usr/local/bin/displayplacer 'id:'$MONITOR' res:'$RES' degree:90'
    sleep 5
    killall -HUP loginwindow
fi"

    do shell script "echo " & quoted form of rotationScript & " > /tmp/rotate_and_logout.sh"
    do shell script "chmod +x /tmp/rotate_and_logout.sh"
    do shell script "nohup /tmp/rotate_and_logout.sh > /dev/null 2>&1 &" with administrator privileges
end if

@jvarn
Copy link
Author

jvarn commented Nov 6, 2024

Also, I can't get any of the portrait screen resolutions listed by /usr/local/bin/displayplacer list to work (black screen).

Resolutions for rotation 90:
  mode 0: res:1824x2736 hz:60 color_depth:4
  mode 1: res:1824x2736 hz:60 color_depth:8 <-- current mode
  mode 2: res:768x1280 hz:60 color_depth:4
  mode 3: res:768x1280 hz:60 color_depth:8
  mode 4: res:1050x1400 hz:60 color_depth:4
  mode 5: res:1050x1400 hz:60 color_depth:8
  mode 6: res:1200x1600 hz:75 color_depth:4
  mode 7: res:1200x1600 hz:75 color_depth:8
  mode 8: res:1200x1600 hz:60 color_depth:4
  mode 9: res:1200x1600 hz:60 color_depth:8
  mode 10: res:480x848 hz:60 color_depth:4
  mode 11: res:480x848 hz:60 color_depth:8
  mode 12: res:768x1360 hz:60 color_depth:4
  mode 13: res:768x1360 hz:60 color_depth:8
  mode 14: res:912x1368 hz:60 color_depth:4 scaling:on
  mode 15: res:912x1368 hz:60 color_depth:8 scaling:on
  mode 16: res:600x800 hz:75 color_depth:4 scaling:on
  mode 17: res:600x800 hz:75 color_depth:8 scaling:on
  mode 18: res:600x800 hz:60 color_depth:4 scaling:on
  mode 19: res:600x800 hz:60 color_depth:8 scaling:on

Well, not that I tried every single one.

@balopez83 balopez83 pinned this issue Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants