Archive for Mac Book Pro

Change Screen Resolution with AppleScript

Recently, I read an article at 9to5Mac about automatically changing your screen resolution based on the program you are using. In my practice, I find that the optimal resolution for my Retina MacBook Pro is different for different programs (due to older eyes and various programs that do not allow larger text). FileMaker Pro, Parallels, Microsoft Word, Firefox, Chrome, PDFpenPro,…. each look the best – to me – at different resolution.

The 9to5Mac article discusses SwitchResX which will (among other things) automate the process of changing your screen resolution based on the active program. The program costs $15 and there is a free trial period.

Of course, this is not a lot for a useful app, but I wondered if switching resolutions could be done by AppleScript or another automation tool. Launching a program can trigger an action in Keyboard Maestro. However, there are no actions that relate to screen resolution. But Keyboard Maestro will allow an AppleScript to be triggered when a program becomes the active window. By combining Keyboard Maestro and AppleScript, I was able to automate changes to the screen resolution for different programs.

After a little internet research and some trial and error, I came up with the following script to change the screen resolution to 1920 x 1200. The System Preferences app is only partially scriptable for my intended purpose. For example, scripting is available to change to the various panes of System Preferences, but I could not specifically change settings. To work around this limitation, I used UI scripting available with the System Events app. To identify the specific UI elements (radio buttons, tab groups,,…) that I needed, I used UI Browser by PFiddlesoft.


Screen Shot 2016-05-10 at 11.21.05 AM

This script can be triggered in Keyboard Maestro with the following macro.

KM - Resize Screen 1920x1200

When the AppleScript is triggered, System Preferences is launched and the resolution is changed. There is a very brief screen flicker and System Preferences is closed. The whole process takes about 1.5 seconds.

The rMBP has five difference resolutions from 1024 x 640 to 1920 x 1200. in the above AppleScript, the “5” in the line “click radio button 5” refers to selecting the highest (of the 5) resolution. Changing the “5” to a different value will change the screen to the following resolutions:

“4” – 1680 x 1050

“3” – 1440 x 900

“2” – 1280 x 800

“1” – 1024 x 640

I have three different macros in Keyboard Maestro for the three highest resolutions. For me, Chrome, Parallels and iMovieĀ  look the best at the highest resolution. Firefox, Outlook and FileMaker Pro look the best at “4” resolution. Lastly, Keyboard Maestro itself looks best at the middle resolution, 3.

Please let me know if you find this helpful.