I’m trying to use AppleScript to rotate the display (90º, 180º, 270º) on a Modbook (an approved modification of a Macbook). On Macbooks/Modbooks beginning June 2009, by option-command-clicking the “Displays” pane in System Preferences, a pop-up button appears allowing one to rotate the display. However, I can not figure out how to access that button using Applescript. Opening the Displays pane using ‘tell application “System Preferences”’, by opening the .prePane file, or using UI scripting, all leave the rotation pop-up button hidden. There are a few AppleScripts around the Web that purport to rotate displays, but I suspect they may all be designed for stand alone displays, since they do not work on my laptop.
I do not know how using AppleScript to tell the UI to click the “Displays” button ‘using {option down, command down}’. That syntax does not work. Is there another? Is there any way to tell AppleScript to hold those buttons down for a bit while I go on to click the “Displays” button?
Alternatively, is there a .plist file that I can access (through the defaults command presumably) that could help rotate the display.
Model: Modbook/Macbook
AppleScript: Version 2.3 (118)
Browser: Safari 531.21.10
Operating System: Mac OS X (10.6)
I find it surprising that Applescript provides no way to click a UI element holding a modifier key down. I’m also curious to see if this question:http://macscripter.net/viewtopic.php?id=32117 gets answered.
This is my modified AppleScript for toggling the external display orientation on my 2011 Macbook Air running Mac OS X 10.9.4
set orientationResult to choose from list {"Standard", "270°"}
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
on setDisplay(thisDisplay, orientationInput)
set rotatable to false
tell application "System Events"
set frontmost of process "System Preferences" to true -- this solves problem of sometimes activate not bringing window to front
tell process "System Preferences"
activate
tell window thisDisplay
activate
tell tab group 1
click radio button 1 -- (click first tab (Monitor), strangly called radio button)
--return UI elements
click pop up button 2 -- click rotation popup button
tell pop up button 2
set menuItemTitles to name of menu items of menu 1
set menuItemToSelect to orientationInput as string
delay 1
click menu item menuItemToSelect of menu 1
end tell
end tell
end tell
if rotatable then
delay 10
-- 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
-- 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
my setDisplay(2, orientationResult)
-- quit system preferences
tell application "System Preferences"
quit
end tell