OS X changes the screen brightness when your MacBook is running on battery power but sadly, there isn’t much else you can trigger when the system detects it is no longer plugged into a power outlet. While the aforementioned feature is useful, an ordinary user can’t do anything with it. Now imagine you’re using a Retina MacBook and would like to reduce your screen’s resolution when it’s running on battery power. One way to do it is manually changing it. Though if you would prefer to automate the process, you will need to make a little effort and be prepared for a little setup procedure. We’re going to show you how to change your screen’s resolution using an AppleScript and ControlPlane – a free Mac App that allows you to create contexts for running apps or scripts. This method works in Mountain Lion but may or may not work on older OS X versions.
Let’s start with understanding the script that we’re going to use. You will not have a UI for choosing the resolution, and any changes will need to be made within the script itself. To get started, open AppleScript Editor and paste the following script into it:
tell application "System Preferences" activate set current pane to pane "com.apple.preference.displays" end tell tell application "System Events" click radio button "Display" of tab group 1 of window 1 of process "System Preferences" click radio button "Scaled" of tab group 1 of window 1 of process "System Preferences" select row 9 of table 1 of scroll area 1 of tab group 1 of window 1 of process "System Preferences" end tell tell application "System Preferences" quit end tell
Don’t run it just yet; open System Preferences and got to the Display preference pane. In the ‘Scaled’ list of resolutions, find the one you want to switch to when you shift to battery power. Next, note its position in that list. As an example, the 1344×768 resolution is the third entry in this list.
Now, find this line in the script and replace the number with three (or whichever position is occupied by your selected resolution in the aforementioned list).
select row 3 of table 1 of scroll area 1 of tab group 1 of window 1 of process "System Preferences"
Run the script now, and it should change the resolution. Save this script as an application.
Next, download and install ControlPlane if you haven’t already done that. We’ve detailed its usage and how it works before, and here we will only address the context that’s needed to get our primary job done. Go to the ‘Contexts’ tab in the app’s preferences and create an ‘On Battery’ context.
Next, go to the ‘Rules’ tab and add a new rule that is triggered each time you’re running on Battery Power (click the plus button and find the relevant option). Assign it to the ‘On Battery’ context you’ve just created. ControlPlane is now all set to switch to the ‘On Battery’ context when it detects that system is running on a battery.
Next, you have to tell ControlPlane what to do when it switches to the ‘On Battery’ context. For this, go to the ‘Actions’ tab and add an Application Action to Open File or Application. Select the application you created from the AppleScript and assign this action to the ‘On Battery’ context you’ve just created. Make sure the action is enabled.
That’s it – unplug your MacBook and the resolution should automatically change to the one you specified.
Assuming you had no problems with the AppleScript, (make sure you test it), ControlPlane is the only thing that might give you trouble. Be careful when you create your contexts and actions. You can use this same script in a number of ways. For example if you connect an external display to your MacBook, you can have it change the resolution of the second display to the one defined in the script. ControlPlane can detect additional displays from the ‘Rules’ tab.
[Script Source: MacSparky]