-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnap.py
executable file
·103 lines (98 loc) · 3.09 KB
/
snap.py
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
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env python3
from applescript import AppleScript as applescript
def left():
script = '''
--- get Dock height
tell application "System Events" to tell process "Dock"
set dock_dimensions to size in list 1
set dock_height to item 2 of dock_dimensions
end tell
--- get the new width and height for the window
tell application "Finder"
set desktop_dimensions to bounds of window of desktop
set new_width to (item 3 of desktop_dimensions) / 2
set new_height to (item 4 of desktop_dimensions) - dock_height
end tell
--- get active window
tell application "System Events"
set frontApp to name of first application process whose frontmost is true
end tell
--- resize window
tell application frontApp
activate
set bounds of window 1 to {0, 0, new_width, new_height}
end tell
'''
applescript(script).run()
def right():
script = '''
--- get Dock height
tell application "System Events" to tell process "Dock"
set dock_dimensions to size in list 1
set dock_height to item 2 of dock_dimensions
end tell
--- get the new width and height for the window
tell application "Finder"
set desktop_dimensions to bounds of window of desktop
set new_width to (item 3 of desktop_dimensions) / 2
set new_height to (item 4 of desktop_dimensions) - dock_height
end tell
--- get active window
tell application "System Events"
set frontApp to name of first application process whose frontmost is true
end tell
--- resize window
tell application frontApp
activate
set bounds of window 1 to {new_width, 0, new_width * 2 + 4, new_height}
end tell
'''
applescript(script).run()
def top():
script = '''
--- get Dock height
tell application "System Events" to tell process "Dock"
set dock_dimensions to size in list 1
set dock_height to item 2 of dock_dimensions
end tell
--- get the new width and height for the window
tell application "Finder"
set desktop_dimensions to bounds of window of desktop
set new_width to (item 3 of desktop_dimensions)
set new_height to ((item 4 of desktop_dimensions) - dock_height) / 2
end tell
--- get active window
tell application "System Events"
set frontApp to name of first application process whose frontmost is true
end tell
--- resize window
tell application frontApp
activate
set bounds of window 1 to {0, 0, new_width, new_height}
end tell
'''
applescript(script).run()
def bottom():
script = '''
--- get Dock height
tell application "System Events" to tell process "Dock"
set dock_dimensions to size in list 1
set dock_height to item 2 of dock_dimensions
end tell
--- get the new width and height for the window
tell application "Finder"
set desktop_dimensions to bounds of window of desktop
set new_width to (item 3 of desktop_dimensions)
set new_height to ((item 4 of desktop_dimensions) - dock_height) / 2
end tell
--- get active window
tell application "System Events"
set frontApp to name of first application process whose frontmost is true
end tell
--- resize window
tell application frontApp
activate
set bounds of window 1 to {0, new_height, new_width, new_height * 2}
end tell
'''
applescript(script).run()