Really simple actions attempted here. Create a TextEdit document and stuff text into it.
set theText to "A bunch of text records, each can be 100 characters long, and over 100 records (using returns)..."
tell application "TextEdit"
activate
set txtDoc to make new document with properties {text:theText}
--Fails here with AppleScript Execution Error and TextEdit even crashdumps.
end tell
Further info on the error is:
TextEdit got an error: AppleEvent handler failed.
/System/Applications/TextEdit.app
-10000
It works fine here — provided that the theText is a single AppleScript text and not a list or something else. Have you checked the input?
BTW. I’ve edited the script in your post so that it appears here in a box with an “Open in Script Editor” button. The trick is to post using plain text and to put three backticks on separate lines above and below, eg.:
```
set theText to "A bunch of text records…"
– etc.
```
Thank you for fixing the script segment to enable opening as code. I visit here so rarely I forgot the trick. But by “backticks” do you mean “backslashes” or “dots” as shown?
The script fetches records from an SQL database. Each record consists of 6-7 columns, and each column result is blank-filled for formatting and terminated with a tab character, then the record is terminated with a return character. And each record is appended to the theText variable to be put into the TextEdit file.
So theText is just a large text variable with a variety of characters. Maybe it’s simply too large. I will try smaller examples to see if those work.
Otherwise even more puzzling why yours works and mine crashes.
Yup my bad. It was a list. Cut and paste error. Sorry.
But TextEdit seems to have a mind of its own, for example using Helvetica font although I specified Menlo in Settings, enforcing line breaks at its own tab stops, etc.
I chose TextEdit but could probably use Notes instead. Or ideally I just need a window to stuff all the results fetched from my database. Key is fixed font for formatting. Will snoop around and see how to create and insert text into a window. And open to ideas.
Sorry. When I saw you’d found the cause of the error you were getting, I forgot to answer your “backtick” question.
It’s character id 96 (hex 0060) — the key to the left of “z” on my British English keyboard. I called it a “backtick” because I’ve seen other people call it that here, but it’s “grave accent” in macOS’s “Show Emoji & Symbols” palette.
For what you are needing (to stash text into a document with fixed font width formatting, I would recommend BBEdit. The free version is fully scriptable, and has a wealth of capabilities for searching and manipulating text as well.