forked from raycast/script-commands
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoggle-flip-screen.template.applescript
executable file
·90 lines (77 loc) · 2.46 KB
/
toggle-flip-screen.template.applescript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/osascript
# How to use this script?
# It's a template which needs further setup. Duplicate the file,
# remove `.template.` from the filename,
# Replace all instances of <display> with the name of your monitor.
# Monitor name can be seen by open System Preferences → Display,
# and look at the window's title name. example: DELL P2212H.
# Replace all instances of <degree> to 90, 180 or 270
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Toggle Flip Screen <display> to <degree>°
# @raycast.mode silent
# Optional parameters:
# @raycast.icon 🖥
# @Documentation:
# @raycast.description Toggle flip (rotate) or revert the <display> to <degree>°
# @raycast.author Yohanes Bandung Bondowoso
# @raycast.authorURL https://github.com/ybbond
use scripting additions
set displayName to "<display>"
set targetDegree to "<degree>°"
if running of application "System Preferences" then
quit application "System Preferences"
end if
tell application "System Preferences"
activate
reveal anchor "displaysDisplayTab" of pane id "com.apple.preference.displays"
end tell
tell application "System Events" to tell process "System Preferences"
set currentCount to 0
repeat while currentCount < 5
if exists tab group 1 of window displayName then
set currentCount to 5
else
delay 0.5
set currentCount to currentCount + 1
end if
end repeat
try
tell window displayName
if exists pop up button 2 of tab group 1 then
tell pop up button 2 of tab group 1
if (value) contains "Standard" then
set currentAction to "Flipping"
click
click menu item targetDegree of menu 1
else
set currentAction to "Reverting"
click
click menu item "Standard" of menu 1
end if
end tell
else
tell pop up button 1 of tab group 1
if (value) contains "Standard" then
set currentAction to "Flipping"
click
click menu item targetDegree of menu 1
else
set currentAction to "Reverting"
click
click menu item "Standard" of menu 1
end if
end tell
end if
end tell
on error errString
log "Some error, please contact me so I can try to fix :)"
end try
end tell
log currentAction & space & "display succeed"
tell application "System Preferences"
quit
end tell
tell application "System Events"
quit
end tell