Skip to content

Instantly share code, notes, and snippets.

@pierwill

pierwill/rodis

Created May 1, 2018
Embed
What would you like to do?
#!/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

This comment has been minimized.

Copy link
Owner Author

@pierwill pierwill commented May 3, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.