Skip to content

Instantly share code, notes, and snippets.

@pierwill
Created May 1, 2018 21:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pierwill/591120ae5a332cb574d27565b0563d0d to your computer and use it in GitHub Desktop.
Save pierwill/591120ae5a332cb574d27565b0563d0d to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# set to executabable with chmod +x
# and place somewhere in your path
from time import sleep
from sys import argv
from subprocess import Popen
# should match the name of the system preferences window
your_monitor = ""
ninety = '''
tell application "System Preferences"
quit
delay 1
launch
activate
reveal pane id "com.apple.preference.displays"
tell application "System Events"
tell process "System Preferences"
delay 1
tell window "''' + your_monitor +'"' + '''
click pop up button "Rotation:" of tab group 1
delay 1
keystroke "90" & return
set success to 0
repeat until success is equal to 1
delay 1
try
tell sheet 1
click button "Confirm"
set success to 1
end tell
on error errText
log errText
delay 1
end try
end repeat
end tell
end tell
end tell
end tell
'''
zero = '''
tell application "System Preferences"
quit
delay 1
launch
activate
reveal pane id "com.apple.preference.displays"
tell application "System Events"
tell process "System Preferences"
delay 1
tell window "''' + your_monitor +'"' + '''
click pop up button "Rotation:" of tab group 1
keystroke "Standard" & return
-- If "Standard" is selected, no confirmation dialog is displayed.
end tell
end tell
end tell
end tell
'''
if argv[1] == '0':
with open('tmp.applescript','w+') as temp:
temp.write(zero)
Popen(['osascript', 'tmp.applescript']).wait()
Popen(['rm', 'tmp.applescript']).wait()
if argv[1] == '90':
with open('tmp.applescript','w+') as temp:
temp.write(ninety)
Popen(['osascript', 'tmp.applescript']).wait()
Popen(['rm', 'tmp.applescript']).wait()
@pierwill
Copy link
Author

pierwill commented May 3, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment