I built a script that selects and copies all text from the front Safari tab, closes the tab, and pastes the text into the front BBEdit document with a couple blank lines of padding.
I'll run it when I have several tabs I want to grab text from, dumping it all into one document, so I'll need a repeat option.
I don't want to hard-code the number of repeats, because that's unpredictable (and I don't want to close Safari tabs willy-nilly). So I want the script to complete once, pop up a choice of "Repeat?" or "Done!", and then repeat, including the pop-up, until the user chooses "Done".
I don't know how to code the repeat. Here's where I'm at:
tell application "Safari" to set the clipboard to (text of current tab of front window) as string
delay 0.1
tell application "Safari"
close current tab of front window without saving
end tell
delay 0.1
tell application "System Events"
tell application "BBEdit" to activate
key code 36
key code 36
end tell
tell application "BBEdit"
activate
paste
end tell
tell application "System Events"
tell application "BBEdit" to activate
key code 36
key code 36
end tell
set theAlertText to "Repeat?"
display alert theAlertText as critical buttons {"Yes", "No"} default button "Yes" cancel button "No"
--> Result: {button returned:"Continue"}
--need repeat code here