Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the '10.4: A set of AppleScripts to rotate the display' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.4: A set of AppleScripts to rotate the display
Authored by: hypert on Oct 31, '07 12:22:33PM
I only use 2 of the 4 possible rotations on my L2065, and they're at 0 and 270 degrees (so I can't use these scripts to toggle between my 2 rotations). Here's a modified version that toggles between 2 rotations (you can set which ones at the top of the script). It's smart enough to figure out what the current rotation is, and then just switch to the other one you defined at the top.

-- v1.1.20060301 (by Conrad Albrecht-Buehler) updated to handle displays with the same name.
-- v2.0 (by hypert) updated to simply toggle between two rotations

(* Set rotationA and rotationB to your two main rotation values.
	1 = Standard
	2 = 90 degrees (clockwise)
	3 = 180 degrees
	4 = 270 degrees
*)
property rotationA : 1
property rotationB : 4

-- this function gets a list of the display preferences windows.
-- needed if you have more than one display that you want to 
-- rotate.  Note: PowerBooks will not rotate their built-in
-- LCDs with this script.
on getDisplays()
	tell application "System Events"
		get properties
		tell process "System Preferences"
			set allDisplays to every window
		end tell
	end tell
	return allDisplays
end getDisplays

-- This function simply clicks the pop-up button that
-- controls rotation, and selects the next in order
-- (either clockwise or counter-clockwise)
on setDisplay(thisDisplay)
	set rotatable to false
	tell application "System Events"
		get properties
		tell process "System Preferences"
			tell window thisDisplay
				tell tab group 1
					click radio button "Display"
					tell group 1
						try
							click pop up button 3
							tell pop up button 3
								repeat with rotationValue from 1 to 4
									if selected of menu item rotationValue of menu 1 is true then
										exit repeat
									end if
								end repeat
								
								if rotationValue is equal to rotationA then
									set rotateMenuItem to rotationB
								else
									set rotateMenuItem to rotationA
								end if
								click menu item rotateMenuItem of menu 1
							end tell
							-- If "Standard" is selected, no confirmation dialog is displayed.
							if rotateMenuItem is not 1 then
								set rotatable to true
							end if
						on error
							log "Can't rotate display. It may be the laptop's built in display."
						end try
					end tell
				end tell
			end tell
			if rotatable then
				delay 3
				-- After rotation, for some reason the confirmation dialog is always in window 1.
				tell window 1
					tell sheet 1
						click button "Confirm"
					end tell
				end tell
			end if
		end tell
	end tell
end setDisplay

-- the "main" part of the script
-- Prompt for change:
--set rotationValue to the button returned of (display dialog "Pick your rotation" with title "Rotation" buttons {"Standard", "270"} default button 1)

-- activate System Preferences
tell application "System Preferences"
	activate
	set current pane to pane "com.apple.preference.displays"
end tell


-- get all the display preference pane windows
-- and rotate each corresponding display
set allDisplays to my getDisplays()
repeat with i from 1 to length of allDisplays
	my setDisplay(i)
end repeat

-- quit system preferences
tell application "System Preferences"
	quit
end tell


[ Reply to This | # ]