Search code examples
macosapplescriptautomator

Change screen refresh rate with applescript


I am currently using 2 screens at my office with my macbook. A few times per day one of the screens colors are very much towards the red spectrum. I can get the screen back to normal coloring by changing the refresh rate to 50 and then back to 60.

I would like to script that this happens automatically every time I login. I was thinking to achieve this with applescript and automator.

What I found on the web so far:

tell application "System Preferences"
 activate
 set current pane to pane "com.apple.preference.displays"
end tell
tell application "System Events"
 tell process "System Preferences"
 click radio button "Display" of tab group 1 of window "BenQ GL2450H (2)"
 delay 1
 ******************************************
 Change refresh rate back and forward, how?
 ******************************************
 end tell
end tell
delay 1
tell application "System Preferences"
 quit
end tell

How the window looks like: enter image description here


Solution

  • Found a shell application to do it with called cscreen

    Note: I only got option -r working when specifying resolution (-x, -y)

    ChangeScreenRefreshRate.sh:

    cscreen -s 2 -x 1920 -y 1080 -r 50
    sleep 5
    cscreen -s 2 -x 1920 -y 1080 -r 60