I use this handler to create a new TextEdit document.
tell application "TextEdit"
repeat
activate
try
do shell script ("sleep 0.1")
tell application "System Events" to tell process "TextEdit"
try
repeat until (exists menu item "New" of menu 1 of menu bar item "File" of menu bar 1)
do shell script ("sleep 0.1")
end repeat
click menu item "New" of menu 1 of menu bar item "File" of menu bar 1
exit repeat
on error errmsg number errnum
if errnum = -1719 or errnum = -25211 then
set my assistTrial to false
exit repeat
end if
end try
end tell
on error errmsg number errnum
set my assistTrial to false
my displayError("Text Edit Start error " & errmsg & " number " & errnum as text)
end try
end repeat
On 5 Jun 2016, at 1:32 PM, Mitchell L Model <
email@hidden> wrote:
This sounds like something completely trivial, but my experiments show it to be fraught with complications.
All I want to do is create a new document in TextEdit, Script Editor, and Script Debugger. It doesn’t need to be saved, but it is OK if it is saved.
Warning: if you approach this you may find yourself creating documents that can’t be saved or closed, or even backed up. If you do, you can execute a script that does “close front doc without saving”.
I have three lines of code that behave differently in the three applications mentioned above, but I’d rather see a real solution rather than providing my code to be debugged.
See
https://discussions.apple.com/message/30269814 for my first attempt at resolving this problem, in the context of TextEdit. (I still haven’t been able to get it to work, despite the help I got on that page.)