I use this AppleScript folder action to center the Finder window of my user folder whenever it is opened.
I have Command-N set to open my user folder.
This can be attached to any folder.
I have Command-N set to open my user folder.
This can be attached to any folder.
AppleScript:
on opening folder xFolder
tell application "Finder"
activate
set the w to the container window of xFolder
-- Get screen dimensions and window dimensions
set screen_bounds to bounds of window of desktop
set screen_width to item 3 of screen_bounds
set screen_height to item 4 of screen_bounds
-- The Finder window opens automatically. We need to reference it.
-- We assume it's the frontmost window (Finder window 1).
-- A small delay might be necessary to ensure the window is fully opened and recognized.
--delay 0.1
-- Get the current bounds of the new window
set window_bounds to bounds of w
set window_width to (item 3 of window_bounds) - (item 1 of window_bounds)
set window_height to (item 4 of window_bounds) - (item 2 of window_bounds)
-- Calculate the centered position
set x_pos to (screen_width / 2) - (window_width / 2)
set y_pos to (screen_height / 2) - (window_height / 2)
-- Set the window's position. Position is top-left corner coordinates.
set position of w to {x_pos, y_pos}
end tell
end opening folder