Skip to content

Instantly share code, notes, and snippets.

@OKsign
Last active January 20, 2022 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OKsign/b86c845b86d97a7762bd4f747eb971f8 to your computer and use it in GitHub Desktop.
Save OKsign/b86c845b86d97a7762bd4f747eb971f8 to your computer and use it in GitHub Desktop.
-- user input
set SizePos to {227, 26, 741, 653}
-- end of user input
tell application "System Events"
set activeApp to (get name of first process where it is frontmost)
end tell
if activeApp is "Google Chrome" then
tell application "Google Chrome"
set Chrome_winName to get title of front window
end tell
tell application "System Events"
tell process "Google Chrome"
click (menu item "Minimize" of menu 1 of menu bar item "Window" of menu bar 1)
end tell
end tell
delay 2
tell application "System Events"
set position of window 1 of process activeApp to {item 1 of SizePos, item 2 of SizePos}
delay 1
set size of window 1 of process activeApp to {item 3 of SizePos, item 4 of SizePos}
end tell
tell application "System Events"
tell process "Google Chrome"
set frontmost to true
delay 0.2
click (menu item Chrome_winName of menu 1 of menu bar item "Window" of menu bar 1)
end tell
end tell
delay 0.5
display notification "Done!" with title "Script 25.1"
return
else
tell application "System Events"
set position of window 1 of process activeApp to {item 1 of SizePos, item 2 of SizePos}
delay 1
set size of window 1 of process activeApp to {item 3 of SizePos, item 4 of SizePos}
delay 0.5
display notification "Done!" with title "Script 25.1"
return
end tell
end if -- activeApp is "Google Chrome"
set switch to 0
if switch is 1 then
-- script: get size and position of active window
tell application "System Events"
set activeApp to (get name of first process where it is frontmost)
end tell
if activeApp is "Google Chrome" then
tell application "Google Chrome"
set Chrome_winName to get title of front window
end tell
tell application "System Events"
tell process "Google Chrome"
click (menu item "Minimize" of menu 1 of menu bar item "Window" of menu bar 1)
end tell
end tell
delay 2
tell application "System Events"
set ppp to get position of window 1 of process activeApp
delay 0.03
set sss to get size of window 1 of process activeApp
delay 0.02
set pos1 to (item 1 of ppp)
set pos2 to (item 2 of ppp)
set siz1 to (item 1 of sss)
set siz2 to (item 2 of sss)
set PosSize to "{" & pos1 & ", " & pos2 & ", " & siz1 & ", " & siz2 & "}"
tell application "System Events"
tell process "Google Chrome"
set frontmost to true
delay 0.2
click (menu item Chrome_winName of menu 1 of menu bar item "Window" of menu bar 1)
end tell
end tell
delay 0.5
set the clipboard to PosSize
delay 0.5
display dialog "Done!" with title "Get Size and Position of Active Window"
end tell
else -- activeApp is not "Google Chrome"
tell application "System Events"
set ppp to get position of window 1 of process activeApp
delay 0.03
set sss to get size of window 1 of process activeApp
delay 0.02
set pos1 to (item 1 of ppp)
set pos2 to (item 2 of ppp)
set siz1 to (item 1 of sss)
set siz2 to (item 2 of sss)
set PosSize to "{" & pos1 & ", " & pos2 & ", " & siz1 & ", " & siz2 & "}"
delay 1
set the clipboard to PosSize
delay 0.5
display dialog "Done!" with title "Get Size and Position of Active Window"
end tell
end if -- activeApp is "Google Chrome"
-- end of script: get size and position of window
end if
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment