forked from raycast/script-commands
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom-window.applescript
executable file
·50 lines (40 loc) · 1.35 KB
/
custom-window.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
#!/usr/bin/osascript
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Custom Window Size
# @raycast.mode silent
# @raycast.packageName System
# Optional parameters:
# @raycast.icon images/custom-window-size.png
# Documentation:
# @raycast.author Astrit
# @raycast.authorURL https://github.com/astrit
# @raycast.description Resize and center the frontmost window to any custom size.
# @raycast.argument1 { "type": "text", "placeholder": "Width" }
# @raycast.argument2 { "type": "text", "placeholder": "Height" }
on run argv
tell application "System Events"
set frontApp to name of first application process whose frontmost is true
end tell
tell application "Finder"
get bounds of window of desktop
end tell
tell application "Finder"
set desktopBounds to bounds of window of desktop
set screenWidth to item 3 of desktopBounds
set screenHeight to item 4 of desktopBounds
end tell
set theApp to frontApp
set appWidth to "" & ( item 1 of argv )
set appHeight to "" & ( item 2 of argv )
tell application frontApp to activate
tell application "System Events" to tell application process frontApp
try
set size of window 1 to {appWidth, appHeight}
set position of window 1 to {(screenWidth - appWidth) / 2.0, (screenHeight - appHeight) / 2.0}
on error errmess
log errmess
-- no window open
end try
end tell
end run