Setting to open new TextEdit document window in center?
I use TextEdit regularly as a scratchpad and to open script outputs. Annoyingly, TextEdit insists on opening a new document window in the top left corner of the screen. Is there any setting I can change to make this the center of the screen or to make it remember the last position of the window?
If this is really not possible, I could 'fake it' and create a script that creates a new TextEdit document and changes the position to the center. But I'd prefer not to do this.
Solution 1:
It seems that TextEdit hardcodes the position for new document windows, and it's not possible to tweak this behaviour using defaults write
to modify TextEdit's Preferences. See this old post from Apple Discussions:
The current version of TextEdit does not maintain a preference in the com.apple.TextEdit.plist file concerning window placement for the document window. What appears to be missing in the TextEdit preferences file is an NSWindow Frame property for the document window itself.
To change the default position of new TextEdit documents there's really only one solution: write a custom AppleScript that can open a new document at your preferred location centered on the screen.
tell application "Finder"
set screen_resolution to bounds of window of desktop
end tell
tell application "TextEdit"
set screenWidth to (item 3 of screen_resolution) - (item 1 of screen_resolution)
set screenHeight to (item 4 of screen_resolution) - (item 2 of screen_resolution)
set screenCentreX to screenWidth / 2
set screenCentreY to screenHeight / 2
activate
make new document
set defaultBounds to bounds of front window
set x1 to item 1 of defaultBounds
set y1 to item 2 of defaultBounds
set x2 to item 3 of defaultBounds
set y2 to item 4 of defaultBounds
set w to x2 - x1
set h to y2 - y1
set centreBounds to {screenCentreX - (w / 2), screenCentreY - (h / 2), screenCentreX + (w / 2), screenCentreY + (h / 2)}
-- "set position" does not work, so we need to fall back on "set bounds"
-- https://stackoverflow.com/q/12803847/190298
set bounds of front window to centreBounds
end tell