AppleScript RTF Document to pasteboard

Doing some research on AttributeString and was thinking why not get the Document Attribute
from complied AppleScript to pasteboard.

Select a AppleScript, it will compile the script before set the data to pasteboard as RTF document.

use framework "Foundation"
use framework "AppKit"
use scripting additions

(**
* [Instance Method]: compileAndReturnError:
*	Compiles the receiver, if it is not already compiled.
**
* - (BOOL)compileAndReturnError:(NSDictionary<NSString *,id> * _Nullable * )errorInfo;
*)

set theMessage to "Select a AppleScript to get RTF Document Attribute"
set thePath to POSIX path of (choose file of type {"com.apple.applescript.script"} with prompt theMessage)
set theURL to current application's |NSURL|'s fileURLWithPath:thePath
set {theScript, theError} to current application's NSAppleScript's alloc()'s initWithContentsOfURL:theURL |error|:(reference)
set {theResult, theError} to (theScript's compileAndReturnError:(reference)) as list
set theScript to theScript's richTextSource()
-- return theScript's className() as text --> NSConcreteMutableAttributedString

set theData to theScript's RTFFromRange:{0, theScript's |length|()} documentAttributes:{DocumentType:current application's NSRTFTextDocumentType}
set pasteboard to current application's NSPasteboard's generalPasteboard()
pasteboard's clearContents()
pasteboard's setData:theData forType:(current application's NSPasteboardTypeRTF)

If you like to see a raw RTF file of compiled AppleScript you could change the last line to this.

pasteboard's setData:theData forType:(current application's NSPasteboardTypeString)