is there a way to center a window of specific app?
I am using a combo of 2 NSWorkSpace notifcations: DidUnhideApplication and AppDidActivate. (i messed with Didactivate as well.)
Basiclly i want the window be centered on the current monitor (i have 2-3) where the mouse is.
With the solution I have below the window erradicately jumps back and forth to the mouse location then centers the window on the display where the mouse currently is. I tried having the window move before unhiding using NSworkspace. But i am curious if there is simple more elegant solution.
How i am currently doing it:
NSWorkspaceDidUnhideApplicationNotification for the app to run this applescript:
use framework "AppKit"
-- Get coordinates from bottom left corner
set |mouseLocation| to current application's NSEvent's mouseLocation()
-- Get current screen resolution
tell application "Finder" to set theDesctopBounds to bounds of window of desktop
-- Get coordinates from top left corner
set |mouseLocation| to {|mouseLocation|'s x, (item 4 of theDesctopBounds) - (|mouseLocation|'s y)}
--set the first windows position based on the current mouse position
tell application "System Events"
set position of first window of application process "MacPass" to |mouseLocation|
end tell
then this trigger: