0

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.

4
  • When I open TextEdit, the window is always in the centre of the screen. It might help if you edit your post to specify what kind of Mac you're using, what version of macOS, and how large your monitor is.
    – Nic
    Apr 4 '20 at 23:21
  • @Nic New "Untitled" documents open in the center as well for you? I use a 2015 4K iMac, latest MacOS.
    – Daan
    Apr 5 '20 at 9:32
  • On my 15" rMBP, new documents in TextEdit go to the middle of the screen. But with an external 1080p monitor, they are shifted slightly to the left. So it does definitely seem related to display resolution.
    – Nic
    Apr 5 '20 at 19:44
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
3
  • 1
    RE: "-- "set position" does not work, so we need to fall back on "set bounds"" -- As a technical point (only), you could use position trough System Events, e.g. tell application "System Events" to tell application process "TextEdit" to set position of window 1 to {x, y} and eliminate some of the math. That said though, if something can be done without using System Events it's generally less of a issue with security permissions in the newer releases of macOS. Apr 5 '20 at 21:05
  • @user3439894 Thanks, that's a super useful note. I think using set bounds is more appropriate for my answer, but I sure do appreciate the explanation about set position.
    – Nic
    Apr 5 '20 at 21:41
  • Thanks for the script and the confirmation that this is (sadly) not possible. I've made a simple script to reposition the windows to the center of my 4K screen: tell application "TextEdit" to set bounds of windows to {683, 357, 1365, 795}
    – Daan
    Apr 27 '20 at 12:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .