I bought an rMBP not long ago and have been looking around for a solution for switching off the built-in screen while watching movies on a TV via HDMI.
For me dimming the brightness via an automated applescript and then turning it back on using the same script solved it.
I assigned a keyboard short cut to the script using the Scenario app from the AppStore. The full script is shown below. It additionally utilizes a self-made app called setKBBrightness to turn off keyboard backlight.
I can post the source code of that too if anyone's interested.
As far as I know dimming the screen doesn't actually turn it of. I use this with display mirroring on to avoid burn-in (due to having the same picture on the built-in screen for too long).
property brightnessLevel : 0.75
property currentLevel : 0
property KeybBrightnessLevel : "930"
ChangeBrightness(brightnessLevel) --Set this value between 0 and 1 to adjust brightness
on ChangeBrightness(BrightnessValue)
tell application "System Preferences"
--activate
set current pane to pane "com.apple.preference.displays"
end tell
tell application "System Events" to tell process "System Preferences"
tell radio button "Display" of tab group 1 of window "Built-in Retina Display" to if value is 0 then
repeat until value is 1
click
end repeat
end if
set currentLevel to value of slider 1 of group 1 of tab group 1 of window "Built-in Retina Display"
--display dialog currentLevel
if currentLevel is 0 then
tell slider 1 of group 1 of tab group 1 of window "Built-in Retina Display" to set value to BrightnessValue
else
tell slider 1 of group 1 of tab group 1 of window "Built-in Retina Display" to set value to 0
end if
end tell
--switching auto keyboard backlight on-off
tell application "System Preferences"
--activate
set current pane to pane "com.apple.preference.keyboard"
end tell
tell application "System Events" to tell process "System Preferences"
if currentLevel is 0 then
--switching on "Adjust keboard brightness in low light", that automatically gets the Keyb. backlight back on
if value of checkbox "Adjust keyboard brightness in low light" of tab group 1 of window "Keyboard" is 0 then
click checkbox "Adjust keyboard brightness in low light" of tab group 1 of window "Keyboard"
end if
else
if value of checkbox "Adjust keyboard brightness in low light" of tab group 1 of window "Keyboard" is 1 then
click checkbox "Adjust keyboard brightness in low light" of tab group 1 of window "Keyboard"
end if
--switching off keyboard backlight
delay 0.5
do shell script "~/Documents/for_scripts/setKBBrightness 0"
end if
end tell
tell application "System Preferences" to quit
if currentLevel is not 0 then tell application "System Events" to key code 124 using control down
end ChangeBrightness