I made tests with an edited version because I'm running the system in French.
set _filename to "Reports"
set _dateStamp to (do shell script "date +_%Y-%m-%d_%H.%M.%S")
set _newFile to (path to desktop as string) & _filename & _dateStamp & ".rtf"
tell application "Safari" to activate
tell application "System Events"
tell application process "Safari"
keystroke "a" using {command down}
delay 0.2
keystroke "c" using {command down}
end tell
end tell
delay 0.5
tell application "Safari" to close current tab of window 1
tell application "TextEdit"
activate
set cod to count documents # ADDED
set f to make new document
repeat until (count documents) > cod # ADDED
delay 0.01
end repeat
# Thanks to the code adde above we are sure that the new document is available
# Extraneous code to be sure that the document is rtf, not text
tell application "System Events" to tell process "TextEdit" to tell menu bar 1 to tell menu bar item 5 to tell menu 1 to tell menu item -1 to enabled
if not result then tell application "System Events" to tell process "TextEdit" to tell menu bar 1 to tell menu bar item 5 to tell menu 1 to click menu item 4 (* switch from Text to Rich Text (RTF) *)
end tell
tell application "System Events"
tell application process "TextEdit"
keystroke "v" using {command down}
end tell
end tell
tell application "TextEdit"
save f in file _newFile
close window 1
quit
end tell
It works well but something bothers me.
Alas, this action is not "seen" by AppleScript and I must be in front of the machine to screenshot to your personal address.get rid of the dialog.
I post a screenshot to your personal address.