Apr 20 10 8:48 PM

Tags : :

Originally Posted by EricN on February 11, 2010 at 7:43am

Up until now my approach to building an accelerometer based screen rotation  app has been to script the "System Preferences" user interface. It has not been very successful. Every attempt I've made has had a major road block. I posted several questions in different scripting sites on the issues. No one seems to have any answers. I have, nonetheless, produced a working prototype, which requires the user, from time to time, to do something that the script can't. It isn't very practical.

Consequently, I've gone in a different direction: find an existing application which already knows how to rotate the screen that I can control with AppleScript. Success!! The display control application, SwitchResX, is readily scriptable, and its scripting hooks plug right into the structure of my existing script. It was easy. The resulting script works well, is robust, and fast. There is a catch, however. SwitchResX is not a free app. It runs 14 euros (~$19 or 6 Lattes). I only other Mac app I've found that can do screen rotation is Display Rotation Menu, which is completely unscriptable. 

The set up is similar to the previous script only you must first download and install SwitchResX — there is a 10 day free trial period. Then download  Daniel Griscom's smsutil (download below this post or from Daniel's site as a part  of his SMSLib). Put smsutil in a sensible location — I put it in ~/Library/Application Support/MacFlipX. Download the MacFlipX AppleScript (below) and launch it in the AppleScript Editor (Utilities folder). Finally, alter the  line of the script beginning 'set smsutilPath to ... ' to include the path to the smsutil utility. (Note that you also may need to "Enable access for assistive devices". You will find the check box for that at the bottom of the "Universal Access" panes in System Preferences.)

Then run the script, and the screen will automatically rotate to match the Modbook's orientation. It is surprisingly fast. Just hit AppleScript Editor's stop button to quit the script. I've also designed the script to work with a regular MacBook (or MacBook Pro) as well. I assume that the MacBook screen is set at an angle of 60 degrees, and I adjust the screen rotation calculations accordingly. To use the script with a MacBook, alter the line of the script that begins: set typeComputer to ...

So far as I know screen rotation only works on a Modbook with a Nvidia graphic chip set (2.13 GHZ Core2Duo, mid-2009), but I tried the script on my first generation Modbook (2.4 GHz, early-2008). The two portrait orientations (90 and 270) looked like garbage. However, the 180 degree rotation looked and worked fine. I've put a section in the script that blocks non-Nvidia MacBooks/Modbooks. If you remove that section to try out your own non-Nvidia Modbook, you are on your own. I take no responsibility. Of course, I'm curious to hear about any interesting results of such experiments.

The download files are below:





This approach has been superseded first by an improved version of MacFlipX, and second by MacFlip, which does not require SwitchResX to be installed. 

Click here to view the attachment
Click here to view the attachment