How can I use AppleScript to type text into a new window? I'm trying to make an applescript that will write itself into a new window of Applescript Editor. But I can't figure out how it will paste itself with quotations. The code I have right now is 

tell application "System Events"
    keystroke "n" using command down
    keystroke "tell application (System Events) keystroke (n) using command down end tell"
end tell
Quotes that are meant to be literal need to be escaped with a backslash and instead of using keystroke, use the following example to create a new AppleScript document containing the wanted code:

tell application "AppleScript Editor"
    set text of (make new document) to "tell application \"System Events\"\n\tkeystroke \"n\" using command down\nend tell"
end tell


Copy and paste the code example above into a new AppleScript document and press the Compile button.  It will then look like:

tell application "AppleScript Editor"
    set text of (make new document) to "tell application \"System Events\"
    keystroke \"n\" using command down
end tell"
end tell


Then press the Run button and it will create a new AppleScript document containing the following:

tell application "System Events"
    keystroke "n" using command down
end tell


Which if you then press the Run button of this new document, it creates a new blank AppleScript document.

Note: Depending on the version of OS X/macOS the tell application "AppleScript Editor" line may be tell application "Script Editor".  You can still paste the example code, as is, into Script Editor and is will automatically remove the Apple portion from AppleScript to show as tell application "Script Editor".