MacOS – Is it possible to change the default window size of a .txt file in TextEdit

customizationmacostextedit

I have a .txt file that I open regularly on my Mac. I would like the TextEdit window of this .txt file to be wider than it normally is.

I can manually increase the window width every time I open the file by left-clicking and dragging the bottom-right corner further to the right. But, it would be much more convenient if the window was wider by default.


I have tried adjusting the TextEdit window size while holding down the shift key.

I have tried adjusting the TextEdit window size while holding down the ⌘ command key.

I have tried adjusting the TextEdit window size while holding down the control key.

After quitting TextEdit and then re-opening the .txt file, none of the above methods recall the previously-set window size.


I am also open to a method that uses AppleScript to set the window size before the file is opened. Here's the AppleScript command that I currently employ to open the file:

do shell script "open -e " & quoted form of Target_Filepath

Best Answer

Instead of changing the default windows size, unless you want to make it permanent and you can just change it in TextEdit > Preferences... then, you can use the following example AppleScript code to open the document in TextEdit and set its size and position on the screen.

First, open the target file, resize and position it on the screen where you want it and the use the following AppleScript code to get the bounds of the document window to use going forward.

tell application "TextEdit" to get bounds of front window

It will return a list, e.g.: {0, 22, 900, 600}, to use with the set bounds ... command.

set targetFile to POSIX path of (path to documents folder) & "Filename.txt"

tell application "TextEdit"
    activate
    open targetFile
    set bounds of front window to {0, 22, 900, 600}
end tell

Note: The reason I'm suggesting the above method is because while one can technically change the default size of the document window programmatically nonetheless since TextEdit doesn't support a position property it makes sense to use the bounds property as the first two list items in the bounds property are its position.

However, if you really want to change the default size prior to opening the target document regardless of it position, here is the information surrounding the default window size. Under TextEdit > Preferences... > New Document > Window Size the default Width is 90 characters and the default Height is 30 lines. With these defaults there are no keys in the com.apple.TextEdit.plist file for this however the corresponding keys are WidthInChars and HeightInChars, which support an integer value.

You'd need to test for the existence of these keys and capture their values so as to have something to reset to after opening the target document. If they are the true defaults, the keys will not exist and you can temporarily set a integer value for these keys, open the target document and then delete the keys. The target document window will open with the new values at the default location of TextEdit's choice, not yours. If you want it in a different location you'd need to use set bounds ..., which defeats programmatically temporarily changing the defaults or the existing setting if not the default values.

Example code using the defaults command:

defaults read $HOME/Library/Containers/com.apple.TextEdit/Data/Library/Preferences/com.apple.TextEdit.plist WidthInChars
defaults read $HOME/Library/Containers/com.apple.TextEdit/Data/Library/Preferences/com.apple.TextEdit.plist HeightInChars

defaults write $HOME/Library/Containers/com.apple.TextEdit/Data/Library/Preferences/com.apple.TextEdit.plist WidthInChars -int 120
defaults write $HOME/Library/Containers/com.apple.TextEdit/Data/Library/Preferences/com.apple.TextEdit.plist HeightInChars -int 50

defaults delete $HOME/Library/Containers/com.apple.TextEdit/Data/Library/Preferences/com.apple.TextEdit.plist WidthInChars
defaults delete $HOME/Library/Containers/com.apple.TextEdit/Data/Library/Preferences/com.apple.TextEdit.plist HeightInChars

These can be used in a do shell script command using set variableName to do shell script "defaults read ..." and then write the logic flow based on what's returned.

If you really want to go this route and need help with the coding, let me know.

Also note that testing surrounding this was done under macOS 10.12 and may be different in previous major OS version releases.