change screen resolution with AppleScript

How can I change change screen resolution using AppleScript? If AppleScript can't do it, what about Terminal?

I tried with examples at How to set screen resolution with a keyboard shortcut on Retina MBP?, but they don't work anymore. I'm on MacBookPro Retina.

This is how the script definitively should start:

    tell application "System Preferences"
        activate
        reveal anchor "displaysDisplayTab" of pane id "com.apple.preference.displays"
    end tell
    tell application "System Events"
        tell application process "System Preferences"
          -- insert magic
        end tell
    end tell

Now I just need to click on "Scaled" and select different display resolutions, but I don't know how these buttons are "called".


Don't know if still works on current versions of OS X, but somebody wrote a command line tool to get and set resolutions a few years ago: https://github.com/jhford/screenresolution


We have created a python script, called Display Manager that allows you programmatically set resolution, bit depth, underscan, mirroring, etc.

Give it a try and let us know if you want additional functionality

https://github.com/univ-of-utah-marriott-library-apple/display_manager