Created
May 1, 2018 21:05
-
-
Save pierwill/591120ae5a332cb574d27565b0563d0d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
based on https://gist.github.com/twlz0ne/4708084