Get developer document reference URL

Example of a script that use WebKit Utilites to search for tags in Apple Developer Document site.

In this example I use the site https://developer.apple.com/documentation/appkit/nstitleposition?language=objc In the site you will find a string of Specify the location of a box’s title with respect to its border. This string will be the string we could use as comment in AppleScriptObjC code. If we like to return to the document reference of that tag we could select the the string from AppleScripObjC code and use a service or script menu script to make google search for the tag.

Or

We do something like, copy the string (tag) and run the script below and paste inside display dialog.

use AppleScript version "2.4"
use framework "Foundation"
use scripting additions
use webLib : script "WebKit Utilities"

(**
* Example reference from Apple Developr Document Reference
* The search tag is: Specify the location of a box’s title with respect to its border
***
* Google search string
* https://www.google.com/search?q=site:developer.apple.com
*
* The idea is to copy strings from Apple developer site to your code and use them as tags.
*
* ex. NSbox has 'Specify the location of a box’s title with respect to its border'
*)

property domain : "https://www.google.com/search?q=site:developer.apple.com" & "%20"

set theDefaultAnswer to "Specify the location of a box’s title with respect to its border"
set theString to (display dialog "Type the tag text from Apple Developer Documentation" default answer theDefaultAnswer)'s text returned
if theString is "false" then return -128

set theUnicodeString to (my stringWithURLPathEncoding:theString) as text
set theURL to domain & theUnicodeString
display URL theURL window size {1024, 850}

on stringWithURLPathEncoding:theURL
	set escapedString to current application's NSString's stringWithString:theURL
	return (escapedString's stringByAddingPercentEncodingWithAllowedCharacters:(current application's NSCharacterSet's URLPathAllowedCharacterSet()))
end stringWithURLPathEncoding: