rotate screen

hi,

i want to rotate my screen via applescript but dont have that much experiance. What I want to do is the following:
Open System preferences, go to displays, select the window of my external display, check whether the screen is already rotated or not and rotate it / set it to default. I tryed the following lines of code:


tell application "System Preferences"
	set current pane to pane "com.apple.preference.displays"
end tell
tell application "System Events"
	tell process "System Preferences"
		tell pop up button 1 of tab group 1 of window "SyncMaster"
			if selected of menu item 1 is true then
				click menu item 2 of menu 1
			else
				click menu item 1 of menu 1
			end if
		end tell
	end tell
end tell
tell application "System Preferences" to quit

i get the following error: žmenu item 1 of pop up button 1 of tab group 1 of window “SyncMaster” of process “System Preferences”" cannot be read. index is not valid (translated, but that what it should be in english)
How do i know how to correctly set the values? i dont know much about applescript, so all i did was searching for code that seemed to fit and just modified it.

More complicated than it looks. I got as far as recognizing what was there, but can’t figure out how to change it.


tell application "System Preferences"
	set current pane to pane "com.apple.preference.displays"
end tell
tell application "System Events"
	tell process "System Preferences"
		tell pop up button 3 of group 1 of tab group 1 of window "SyncMaster"
			click
			set V to value
			if V is "Standard" then beep 3
		end tell
	end tell
end tell
tell application "System Preferences" to quit

Hi Adam,

this works (10.5.8)


tell application "System Preferences"
	set current pane to pane "com.apple.preference.displays"
end tell
tell application "System Events"
	tell process "System Preferences"
		tell pop up button 3 of group 1 of tab group 1 of window 1
			set V to value -- it's not necessary to click the button to get the value
			if V is "Standard" then beep 3
			click
			pick menu item "180°" of menu 1
		end tell
	end tell
end tell
-- tell application "System Preferences" to quit

but you have to click also the Confirm button

thank you for your comments, i changed what you wrote to


tell application "System Preferences"
	set current pane to pane "com.apple.preference.displays"
end tell
tell application "System Events"
	tell process "System Preferences"
		tell pop up button 1 of tab group 1 of window "SyncMaster"
			click
			set V to value
			if V is "Standard" then
				pick menu item "90°" of menu 1
			else
				pick menu item "Standard" of menu 1
			end if
		end tell
		--click button 1 of sheet 1 of window 1 --this i want to implement
	end tell
end tell
tell application "System Preferences" to quit

and it works great! but i also want to click the accept-button automatically. I figured out that the path to the button is “button 1 of sheet 1 of window 1” by using UI Browser and i implemented it where i have put it in comment but it says

does anyone know how to fix it?

try this


tell application "System Preferences"
	set current pane to pane "com.apple.preference.displays"
end tell
tell application "System Events"
	tell process "System Preferences"
		tell window "SyncMaster"
			tell pop up button 1 of tab group 1
				click
				set V to value
				if V is "Standard" then
					pick menu item "90°" of menu 1
				else
					pick menu item "Standard" of menu 1
				end if
			end tell
			repeat until exists sheet 1
				delay 0.2
			end repeat
			click button 1 of sheet 1
		end tell
	end tell
end tell
tell application "System Preferences" to quit

thank you, i just had to add a line because for some reason the sheet doesnt appear when setting back to default, so this did not stop. This is the final version now (if someone is interested)


tell application "System Preferences"
	set current pane to pane "com.apple.preference.displays"
end tell
tell application "System Events"
	tell process "System Preferences"
		tell window "SyncMaster"
			tell pop up button 1 of tab group 1
				click
				set V to value
				if V is "Standard" then
					pick menu item "90°" of menu 1
				else
					pick menu item "Standard" of menu 1
				end if
			end tell
			if V is "Standard" then
				repeat until exists sheet 1
					delay 0.2
				end repeat
				click button 1 of sheet 1
			end if
		end tell
	end tell
end tell
tell application "System Preferences" to quit

thanks for all the help

Glad to see this thread completed. The verb “pick” was where I went wrong. Forgot that was the way to choose a drop-down menu item. :slight_smile:

hi everyone!
im new to osx as well. i would like to have an applescript for the internal display of my macbook to rotate. im using snow leopard and the rotate option is hidden in the displays option menu by default. nevertheless i found out that u can “unhide” it by holding option+cmd while clickin on displays. i tried the abode script. i removed the synchmaster lines and one end tell line because i assumed that they’d belong to external display. but its not working.

so this is what the script should do:
open system prefs, hold down optio+cmd, click on displays, change to 90, close system prefs

i would really appreciate if someone could help me. thanks!

Model: macbook 6.1
AppleScript: 2.1.1
Browser: Firefox 3.5.7
Operating System: Mac OS X (10.6)

henr1k’s question about how to rotate a MacBook’s internal display using AppleScript is resolved is this forum post.

http://macscripter.net/viewtopic.php?pid=124816#p124816