How to use Xcode to make a Safari extension that works

Sorry, I can’t seem to find a command for “Consider this text to be a script.”

For years I used two Safari extensions, or scripts I put in the “Contextual Menu Items folder”

These were

  • send an image to Google Images for identification
  • do an AppleScript that sends the current Safari selection to Wikipedia

Now neither of these appear in the side menu (the right-click menu, whatever you call it)

I have been told I must use Xcode now. I’m very familiar with Xcode, but not in the last year or so.

So can someone give me a link to the documentation for creating Safari Extensions with Xcode? I have no idea where to start. All I need to do is place them somewhere and click whatever boxes I need. One of them is pure AppleScript except for a “do Javascript” that gets the Safari selection. The other one appears to be all Javascript, of which I know nothing.

Here’s the Wikipedia one, which I wish to return to the Contextual Menu Items folder in Safari.

	set selectedText to do JavaScript "window.getSelection()+'';" in front document -- get the selected text
end tell

if selectedText is not "" then -- if there is a selection
	set selectedText to my formatForWiki(selectedText) -- format for Wikipedia
	set wikiURL to "" & selectedText -- add selection to end of Wiki URL
	open location wikiURL -- launch Wikipedia in default browser
end if

-- Subroutine to replace blanks with underscores for Wikipedia
to formatForWiki(theString)
	set AppleScript's text item delimiters to space
	set theWords to (words of theString)
	set AppleScript's text item delimiters to "_"
	set theString to theWords as text
	set AppleScript's text item delimiters to ""
	return theString
end formatForWiki

So this is a straighforward pure AppleScript except for the call to Javascript.

How do I make it into a Safari Extension that will appear in the Contexual Menu Items? As I said, I had this working for years, used it constantly and now Apple has done this.