How to create Markdown, RTF, HTML, MediaWiki, LaTeX, Mathematica links using Hook URLs to one or more selected items in Finder

An updated and more robust version of the same script for Hook 2 is the following:

set theType to chooseRefType({"Markdown", "MediaWiki", "RTF", "HTML", "LaTeX", "Mathematica"}) of me


tell application "Finder"
	set selectedFiles to the selection
	if selectedFiles is {} then error "Please select some contents."
	
	set theLinks to ""
	repeat with aFile in selectedFiles
		set filePath to POSIX path of (aFile as alias)
		set fileAddress to "file://" & filePath
		set fileName to name of aFile
		tell application "Hook"
			set hookURL to address of (make bookmark with properties {address:fileAddress, name:fileName})
			if theType is "RTF" then
				set the theLink to createLink(fileName, hookURL, "HTML") of me
				set theLinks to theLinks & theLink & "<br />"
			else
				set the theLink to createLink(fileName, hookURL, theType) of me
				set theLinks to theLinks & theLink & return
			end if
		end tell
	end repeat
	if theType is "RTF" then set the theLinks to createLink(fileName, theLinks, "RTF") of me
	set the clipboard to theLinks
	
end tell


on chooseRefType(linkType)
	set linkType to item 1 of (choose from list linkType with prompt "Choose the type of link:" default items {"Markdown"})
	return linkType
end chooseRefType

on createLink(linkText, linkURL, linkType)
	if linkType is "RTF" then
		set linkHTML to "<html>" & linkURL & "</html>"
		set the clipboard to linkHTML
		set theLink to do shell script "pbpaste | textutil -stdin -format html -convert rtf -stdout" as «class RTF »
	else if linkType is "Markdown" then
		set theLink to "[" & linkText & "](" & linkURL & ")"
	else if linkType is "MediaWiki" then
		set theLink to "[" & linkURL & " " & linkText & "]"
	else if linkType is "LaTeX" then
		set theLink to "\\href{" & linkURL & "}{" & linkText & "}"
	else if linkType is "HTML" then
		set theLink to "<a href=\"" & linkURL & "\">" & linkText & "</a>"
	else if linkType is "Mathematica" then
		set theLink to "Hyperlink[\"" & linkText & "\",\"" & linkURL & "\"]"
	end if
	return theLink
end createLink
2 Likes