Can I use AppleScript to paste a web text clip appended with source attribution and a timestamp, while maintaining embedded links? Complete newbie here so please let me know if I need to clarify or otherwise improve my question. I have searched multiple times using different keywords and have not been able to find a solution to my issue, or make the ones I hoped were a solution work for me.

I want to create a AppleScript script that when triggered will allow me to paste a web text clip appended with source attribution and a timestamp, without loosing any embedded links within the selected text.

Here is a screen shot of what I want to achieve: 



Not knowing much of anything programming wise, I was able to cobble together the following AppleScript script after a few days of web searching. 

-- clear the clipboard
tell application "Finder"
    set the clipboard to " "
    delay 0.1
end tell

-- copy selected text
tell application "Safari"
    activate
    tell application "System Events"
        tell process "Safari"
            keystroke "c" using {command down}
            delay 0.1
        end tell
    end tell
end tell

-- open and paste web clip into specified TextEdit file 
tell application "TextEdit"
    activate
    open "Macintosh HD:Users:Web:Documents:Web Text Clips:Web_Text_Clips.rtf"
    delay 0.2
    tell application "System Events"
        tell process "TextEdit"
            keystroke "v" using {command down}
            delay 0.1
        end tell
    end tell
end tell

-- get, format and copy source info and timestamp 
tell application "Safari"
    activate
    set theLongDate to current date
    set theWindowName to the name of the front window
    set theURL to the URL of the front document
    set writeString to "- - - - - " &amp; return &amp; "From: " &amp; theURL &amp; return &amp; "Page Title: " &amp; theWindowName &amp; return &amp; "Date: " &amp; theLongDate
    set the clipboard to writeString
end tell

-- paste source info and timestamp into predefined position of the specified TextEdit file 
tell application "TextEdit"
    activate
    tell application "System Events"
        tell process "TextEdit"
            keystroke (ASCII character 31) using command down
            keystroke return
            keystroke return
            keystroke "v" using {command down}
            delay 0.1
        end tell
    end tell
end tell

-- copy content of specified TextEdit file 
tell application "TextEdit"
    activate
    tell application "System Events"
        tell process "TextEdit"
            keystroke "a" using {command down}
            keystroke "c" using {command down}
            delay 0.1
        end tell
    end tell
end tell

-- delete content of specified TextEdit file 
tell application "TextEdit"
    activate
    tell application "System Events"
        tell process "TextEdit"
            keystroke "a" using {command down}
            keystroke "x" using {command down}
            delay 0.1
        end tell
    end tell
end tell

-- save specified TextEdit file and quit TextEdit
tell application "TextEdit"
    save "Macintosh HD:Users:Web:Documents:Web Text Clips:Web_Text_Clips.rtf"
    quit
end tell


I was forced into this workaround because when I used the set command the embedded links got expunged from the selected web text.

While this script does work, it is quite cumbersome and slow. I have tried all sorts of different things, including some shell script commands, but so far nothing else has worked.

Can anyone help me in creating a more elegant and faster script that still maintains the embedded links in the selected web text?

I am running macOS Sierra 10.12.6.
I'm a bit confused by your script, it seems to copy and paste and delete and save, so if I misunderstood your intended use, I apologize. It seems to me like you want a file saved in that Web Clips folder that just contains what you had selected in Safari with the link, title, and date. I would write this as an HTM file rather than a text file, and here's the code I used with inline comments.

set myFolder to ((path to users folder) as text) &amp; "Web:Documents:Web Text Clips:"
set myFile to myFolder &amp; "Web_Text_Clips.htm"

tell application "Safari"
set theLongDate to current date
set theWindowName to the name of the front window
set selectedText to (do JavaScript "(''+getSelection())" in document 1) --use javascript to get what part of the page is selected
set theURL to the URL of the front document
end tell

set myFolder to POSIX path of (myFolder as alias) --convert to posix path for use in the command line
set myFile to quoted form of (myFolder &amp; myFile) --append the file name to the end of the file path
do shell script "touch " &amp; myFile --create the htm file

--Add content to the HTM document
newHTM(myFile) --Add the HTM doctype and opening tags.
addElement("p", "--------", myFile) --"p" is the htm tag for a paragraph, and we want this to be it's own paragraph. 
addElement("p", "From: &lt;a href=" &amp; theURL &amp; "&gt;" &amp; theURL &amp; "&lt;/a&gt;", myFile) --a bit more complex, adding a paragraph with a link (&lt;a&gt; is the link tag)
addElement("p", "Page Title: " &amp; theWindowName, myFile) --Adding a paragraph for the Page Title
addElement("p", "Date: " &amp; theLongDate, myFile) --Adding a paragraph for the Date line.
closeHTM(myFile) --Add the closing HTML tags.

------------HANDLERS------------
on newHTM(filePath)
    do shell script "printf '&lt;!doctype html&gt;\n&lt;html lang=\"en\"&gt;\n&lt;head&gt;\n\t&lt;title&gt;Web Clips&lt;/title&gt;\n\n&lt;/head&gt;\n\n&lt;body&gt;\n\t' &gt; " &amp; filePath
end newHTM

on closeHTM(filePath)
    do shell script "printf '\n\t&lt;/body&gt;\n&lt;/html&gt;' &gt;&gt; " &amp; filePath
end closeHTM

on addElement(elem, htm, filePath)
    set htm to "\t\t&lt;" &amp; elem &amp; "&gt;" &amp; htm &amp; "&lt;/" &amp; elem &amp; "&gt;\n"
    do shell script "printf '" &amp; htm &amp; "' &gt;&gt; " &amp; filePath
end addElement


This script preserves the link by using HTML to "embed" the link. It will open in your default browser. It appeared to me, from your script, that this file only contains the latest web clipping, so that's how I wrote it. If, however, you want this file to contain a list of web clippings, the script would need to be edited. Either way, I hope this gives you a good start. For readability, I put the adding of html code in handlers below the body of the code.