Extract text note from PDF (Skim.app) and make new document in Script Editor

Here is example of PDF document that was created in TextEdit. From the image below you will
see yellow block with some AppleScript code. This code have been copy from the PDF document and text note have been with its content. This would properly be the only user input that need to be done to extract its content.

The idea is to extract the AppleScript code and make new document with Script Editor with the code. To make this possible in Skim we also need to set hidden preference.

defaults write -app Skim SKIncludeNewlinesFromEnclosedText -boolean true

Here is the AppleScript we will use to make a new document in Script Editor with the code.

set highlightText to its notesFromPageNumber(1) as string

tell application "Script Editor"
	set theObject to make new document with properties {text:highlightText}
end tell

on notesFromPageNumber(pageNumber)
	tell application "Skim"
		tell page pageNumber of front document
			set noteObjects to its notes
			set {idx, noteList} to {1, {}}
			repeat while idx ≤ noteObjects's length
				set the end of noteList to text of (item idx of noteObjects) as string
				set idx to idx + 1
			end repeat
			return noteList
		end tell
	end tell
end notesFromPageNumber

This approach is something I have done before with Preview.app
This time we use Skim.app instead and text note. Text note in Skim is a special object that only are viewed in Skim and not ex. Preview It means the PDF document is clean and we could include anything we want and later extract its contents.