Skip to content

Instantly share code, notes, and snippets.

@ChristoferK
Last active November 3, 2022 06:34
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChristoferK/990c63e831fbf09f6ef792a3a0b92e38 to your computer and use it in GitHub Desktop.
Save ChristoferK/990c63e831fbf09f6ef792a3a0b92e38 to your computer and use it in GitHub Desktop.
[Centre Window on Screen] Centres the frontmost window on screen #AppleScript #SystemEvents #UI #window #position
use application "System Events"
property process : a reference to (first process whose frontmost = true)
property window : a reference to front window of my process
property display : a reference to scroll area 1 of process "Finder"
if not (my window exists) then return
set [width, height] to size of my window
set [screenX, screenY] to size of my display
set position of my window to [(screenX - width) / 2, (screenY - height) / 2]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment