-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscrpt.scpt
58 lines (51 loc) · 1.77 KB
/
scrpt.scpt
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
# PART 1
# Create select dropdown of window sizes and capture user selection
set windowSizeOptions to {"1920x1080", "1600x900", "1366x768", "1280x720"}
set selectedSizeOption to choose from list windowSizeOptions with prompt "Select window size" default items {"1280x720"}
# If 'Cancel' button is clicked on, exit program
if selectedSizeOption is false then
error number -128
end if
# PART 2
# Calculate the resize dimentions
set the text item delimiters to "x"
set {appWidth, appHeight} to {text item 1, text item 2} of item 1 of the selectedSizeOption
tell application "Finder"
set screenResolution to bounds of window of desktop
end tell
set {screenWidth, screenHeight} to {item 3, item 4} of screenResolution
set yAxis to (screenHeight - appHeight) / 2 as integer
set xAxis to (screenWidth - appWidth) / 2 as integer
# PART 3
# Get active window while ignoring the resize window app
tell application "System Events"
set frontmostProcess to first process where it is frontmost
set visible of frontmostProcess to false
repeat while (frontmostProcess is frontmost)
delay 0.2
end repeat
set secondFrontmostProcess to name of first process where it is frontmost
set frontmost of frontmostProcess to true
end tell
set activeApp to secondFrontmostProcess
# PART 4
# Pefrom the app resize
tell application activeApp
activate
reopen
set the bounds of the first window to {xAxis, yAxis, appWidth + xAxis, appHeight + yAxis}
end tell
(*
# Using system events
# Leads to error, where app doesn't have the right permission
# even though it's already given
tell application "System Events"
tell application process activeApp
activate
reopen
set frontWindow to the first window
set position of frontWindow to {xAxis, yAxis}
set size of frontWindow to {appWidth, appHeight}
end tell
end tell
*)