Apple - Keyboard shortcut flip screen

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:

enter image description here

AppleScript application, named Flip Display 180°:

enter image description here

Automator service workflow, also named Flip Display 180°:

Code: open -a 'Flip Display 180°'

enter image description here

System Preferences > Security & Privacy > Privacy > Accessibility:

enter image description here

System Preferences > Keyboard > Shortcuts > Services > General > Flip Display 180°

enter image description here


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 additional delay commands may or may not be needed. Adjust values of and or add/remove the delay 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:

enter image description here


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'