Keyboard shortcut flip screen
How can I create a keyboard shortcut that flips my screen upside down?
I know how to enable this setting in System Preferences but I want to be able to bind it to a shortcut.
Is it possible to make the same keyboard shortcut revert the display back to normal orientation?
I wrote a program named displayplacer that makes this easy to do via a terminal command. You could bind this to a keyboard shortcut with a program like BetterTouchTool or maybe Automator. Works with all macOS versions above 10.6.
Example to flip 180: displayplacer 'id:123467890 res:1920x1200 scaling:off origin:(0,0) degree:180'
Example to flip 0: displayplacer 'id:123467890 res:1920x1200 scaling:off origin:(0,0) degree:0'
The following has been tested under macOS Sierra 10.12.5 and macOS High Sierra 10.13.3, and works without any issue on my system.
Using the example AppleScript code, from my original answer, saved as an AppleScript application named Flip Display 180° and added to System Preferences > Security & Privacy > Privacy > Accessibility, so as to allow it to process the code, I then used an Automator service workflow, also named Flip Display 180°, to open the AppleScript application of the same name, while assigning the following keyboard shortcut: ⇧⌃⌘R
-
Note that the keyboard shortcut ⇧⌃⌘F, which worked under OS X 10.8.5, conflicted with a system default keyboard shortcut under macOS 10.12.5, macOS 10.13.3 and why I changed it. You may have to use a different keyboard shortcut and as usual you have to choose one that isn't already assigned in any application that has focus when pressed to activate this Automator service workflow.
-
I also ran the following command, in Terminal, so as not to show the Dock Tile for the AppleScript application on the Dock:
defaults write '/Applications/Flip Display 180°.app/Contents/Info.plist' LSUIElement -bool yes
That said, if the UI for Displays in System Preferences in macOS High Sierra on your system different for some undisclosed reason then the example AppleScript code will need to be modified to accommodate the the differences between what works on my system and yours. If it does need to be modified, I'd imagine it wouldn't be that hard to figure out.
The following images show the relevant details:
System Preferences > Displays > Display, as shown on my system:
AppleScript application, named Flip Display 180°:
Automator service workflow, also named Flip Display 180°:
Code: open -a 'Flip Display 180°'
System Preferences > Security & Privacy > Privacy > Accessibility:
System Preferences > Keyboard > Shortcuts > Services > General > Flip Display 180°
For the time being I'm leaving my original answer at the bottom portion of this answer as it does work as stated under OS X 10.8.6 and may be beneficial for other users.
Original Answer:
I know you are using macOS High Sierra and maybe you can use what works for me under OS X 10.8.6.
The following example AppleScript code used in a Run AppleScript action in an Automator service workflow flips the Display 180° when I press: ⇧⌃⌘F
if running of application "System Preferences" then
quit application "System Preferences"
delay 1
end if
tell application "System Preferences"
reveal anchor "displaysDisplayTab" of pane id "com.apple.preference.displays"
delay 1
tell application "System Events"
tell pop up button "Rotation:" of tab group 1 of window 1 of application process "System Preferences"
if (value) contains "Standard" then
click
click menu item "180°" of menu 1
my clickConfirmButton()
else
click
click menu item "Standard" of menu 1
end if
end tell
end tell
quit
end tell
on clickConfirmButton()
set wasClicked to false
repeat until wasClicked
delay 0.5
tell application "System Events"
try
click button "Confirm" of sheet 1 of window 1 of application process "System Preferences"
set wasClicked to true
end try
end tell
end repeat
end clickConfirmButton
- Note that the value of the
delay
commands may need to be adjusted for your system, and or additionaldelay
commands may or may not be needed. Adjust values of and or add/remove thedelay
commands as appropriate.
Note: The example AppleScript code is just that and does not employ any other error handling then what's shown and is meant only to show one of many ways to accomplish a task. The onus is always upon the User to add/use appropriate error handling as needed/wanted.
Automator service workflow:
This script has tested on macos 10.14 for Chinese users.
If you're using other language, please modify the button name to your language.
In script "LG Ultra HD"
means your monitor's name, this is useful if you have more than 2 monitors, otherwise, you can replace (first window whose name is "LG Ultra HD")
by window 1
if running of application "System Preferences" then
quit application "System Preferences"
delay 1
end if
tell application "System Preferences"
reveal anchor "displaysDisplayTab" of pane id "com.apple.preference.displays"
delay 1
tell application "System Events"
tell pop up button "旋转:" of tab group 1 of (first window whose name is "LG Ultra HD") of application process "System Preferences"
if (value) contains "标准" then
click
click menu item "270°" of menu 1
my clickConfirmButton()
else
click
click menu item "标准" of menu 1
end if
end tell
end tell
quit
end tell
on clickConfirmButton()
set wasClicked to false
set i to 10
repeat until wasClicked or i ≤ 0
delay 0.5
tell application "System Events"
try
click button "确认" of sheet 1 of (first window whose name is "LG Ultra HD") of application process "System Preferences"
set wasClicked to true
end try
end tell
set i to i - 1
end repeat
end clickConfirmButton