Application Runs from SD and SE but quits as an app

This is odd. I’ve been using a version of this script as an applet for months. It runs just fine from SD and SE, but when saved as an applet and it quits immediately. I’ve saved it as a new app with a new name, from both SD and SE. I’ve made sure it has permission for Accessibility.

use AppleScript version "2.4"
use scripting additions
use script "Myriad Tables Lib" version "1.0.6"
use script "List"

--use framework "Foundation"
property lastpaletteTablePosition : {}
property initialSelection : {}
property palletHeight : 460.0
property lastSearch : "LA Times"
property tolPage : "http://news.latimes.com/cgi-bin/frame_set.cgi?name=tol"

if lastpaletteTablePosition is {} then
	set {paletteTableX, paletteTableY} to {0, 0}
else
	set {paletteTableX, paletteTableY} to lastpaletteTablePosition
end if
set paletteTablePosition to {paletteTableX, paletteTableY}

set tableDisplayData to {"Amazon", "Google", "Google Define", "Google News", "Google Video", "Wiki", ¬
	"IMDB via Google", "IMDB Cast and Crew via Google", "IMDB", "ParseIMDBCast", ¬
	"LATimes via Google", "LATimes", "TOL Headlines", "TOL Byline", "TOL Words in Story", "TOL Names and Phrases", ¬
	"TV Guide", "Amazon Prime", "AppleTV", "Disney+", "Hulu", "Netflix"}

set palletHeight to ((count of tableDisplayData) * 29)
--http://www.google.com/search?q=define:+blog
set tableTitle to "Script Pallet"
set okName to "Go"
set cancelName to "Close"
set extraName to "Refresh"
repeat
	try
		set clipBoardString to the clipboard
		set clipBoardString to the clipboard as text
		set displayString to paragraphs of (clipBoardString as text)
		set lastSearch to item 1 of displayString
	on error
		set clipBoardString to lastSearch
		set displayString to {lastSearch}
	end try
	if the (count of displayString) > 1 then
		set displayString to item 1 of displayString & "..."
	end if
	
	set tablePrompt to "Searching for “" & displayString & "”"
	
	set myTable to make new table with data tableDisplayData ¬
		with prompt tablePrompt ¬
		with title tableTitle ¬
		empty selection allowed true ¬
		initially selected rows initialSelection ¬
		multiple selections allowed true ¬
		row template {"", missing value} ¬
		with double click means OK
	
	modify table myTable initial position paletteTablePosition ¬
		OK button name okName ¬
		cancel button name cancelName ¬
		extra button name extraName
	tell me to activate
	set tableResult to display table myTable ¬
		with extended results
	set whichButton to button number of tableResult
	set userSelection to values selected of tableResult
	if userSelection is not {"ParseIMDBCast"} then
		set initialSelection to rows selected of tableResult
	end if
	set lastpaletteTablePosition to final position of tableResult
	set {paletteTableX, paletteTableY, paletteTableW, paletteTableH} to lastpaletteTablePosition
	if paletteTableX < 1 then set paletteTableX to 0
	if paletteTableY < 1 then set paletteTableY to 0
	set paletteTableH to palletHeight
	set paletteTableW to 200
	
	set lastpaletteTablePosition to {paletteTableX, paletteTableY}
	set paletteTablePosition to lastpaletteTablePosition
	set userSelection to values selected of tableResult
	if userSelection is not {} and whichButton is not 2 then
		my RunTheScript(userSelection)
	end if
	
end repeat
on FormSearchURL(searchPreString, searchString, searchPostString)
	set searchPreString to "https://www.imdb.com/find?ref_=nv_sr_fn&q="
	set searchPostString to "&s=all"
	set searchString to searchPreString & searchString & searchPostString
	return searchString
end FormSearchURL

on RunTheScript(scriptList)
	local scriptName
	set clipBoardString to the clipboard
	set searchString to clipBoardString
	set searchString to paragraph 1 of searchString
	set searchString to words of searchString
	set AppleScript's text item delimiters to {"+"}
	set searchString to searchString as text
	
	repeat with scriptName in scriptList
		set scriptName to scriptName as text
		--{"ParseIMDBCast", "Search Google IMDB", "Search Google", "Search LATimes", ¬
		--"Search Netflix", "Search Wiki"}
		if scriptName is "ParseIMDBCast" then
			try
				return my ParseIMDBCast(clipBoardString)
			end try
		else
			if scriptName is "Google" then
				set searchPreString to "https://www.google.com/webhp?client=safari&rls=en&ie=UTF-8&oe=UTF-8#q="
				set searchPostString to ""
				set searchURL to searchPreString & searchString & searchPostString
				tell application "Safari" to open location searchURL
				
			else if scriptName is "Google Define" then
				--http://www.google.com/search?q=define:+blog
				set searchPreString to "http://www.google.com/search?q=define:+"
				set searchPostString to "&s=all"
				set searchURL to searchPreString & searchString & searchPostString
				tell application "Safari" to open location searchURL
			else if scriptName is "AppleTV" then
				
				set searchPreString to "http://www.google.com/search?q="
				set searchPostString to "+site:tv.apple.com"
				
				set searchURL to searchPreString & searchString & searchPostString
				tell application "Safari" to open location searchURL
				
			else if scriptName is "Disney+" then
				
				set searchPreString to "http://www.google.com/search?q="
				set searchPostString to "+site:disneyplus.com"
				
				set searchURL to searchPreString & searchString & searchPostString
				tell application "Safari" to open location searchURL
				
				
			else if scriptName is "Google News" then
				set searchPreString to "https://www.google.com/search?biw=1418&bih=893&tbm=nws&ei=A8caW5iPN8Of0wKE0qLIBA&q="
				set searchPostString to "&s=all"
				set searchURL to searchPreString & searchString & searchPostString
				tell application "Safari" to open location searchURL
				
			else if scriptName is "Google Video" then
				set searchPreString to "https://www.google.com/search?q="
				set searchPostString to "&tbm=vid&source=lnms&sa=X&ved"
				set searchURL to searchPreString & searchString & searchPostString
				tell application "Safari" to open location searchURL
				
			else if scriptName is "IMDB via Google" then
				set searchPreString to "https://www.google.com/webhp?client=safari&rls=en&ie=UTF-8&oe=UTF-8#q=IMDB:"
				set searchPostString to ""
				set searchURL to searchPreString & searchString & searchPostString
				tell application "Safari" to open location searchURL
			else if scriptName is "IMDB Cast and Crew via Google" then
				set searchPreString to "https://www.google.com/webhp?client=safari&rls=en&ie=UTF-8&oe=UTF-8#q=IMDB: full cast and crew "
				set searchPostString to ""
				set searchURL to searchPreString & searchString & searchPostString
				tell application "Safari" to open location searchURL
				
			else if scriptName is "IMDB" then
				set searchPreString to "https://www.imdb.com/find?ref_=nv_sr_fn&q="
				set searchPostString to "&s=all"
				set searchURL to searchPreString & searchString & searchPostString
				tell application "Safari" to open location searchURL
				
			else if scriptName is "LATimes" then
				set searchPreString to "https://www.latimes.com/search/?q="
				set searchPostString to ""
				set searchURL to searchPreString & searchString & searchPostString
				tell application "Safari" to open location searchURL
				
			else if scriptName is "LATimes via Google" then
				set searchPostString to "+site:latimes.com"
				set searchPreString to "http://www.google.com/search?q="
				set searchURL to searchPreString & searchString & searchPostString
				tell application "Safari" to open location searchURL
				
			else if scriptName is "TV Guide" then
				set searchPreString to "http://www.tvguide.com/search/?keyword="
				set searchPostString to ""
				set searchURL to searchPreString & searchString & searchPostString
				tell application "Safari" to open location searchURL
				
			else if scriptName is "Netflix" then
				set searchPreString to "https://www.google.com/webhp?client=safari&rls=en&ie=UTF-8&oe=UTF-8#q=netflix.com:"
				set searchPostString to ""
				set searchURL to searchPreString & searchString & searchPostString
				tell application "Safari" to open location searchURL
			else if scriptName is "Amazon" then
				--https://www.amazon.com/s?field-keywords=homecoming
				set searchPreString to "https://www.amazon.com/s?field-keywords="
				set searchPostString to ""
				set searchURL to searchPreString & searchString & searchPostString
				tell application "Safari" to open location searchURL
				
			else if scriptName is "Amazon Prime" then
				--https://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Dinstant-video&field-keywords=homecoming
				
				set searchPreString to "https://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Dinstant-video&field-keywords="
				set searchPostString to ""
				set searchURL to searchPreString & searchString & searchPostString
				tell application "Safari" to open location searchURL
			else if scriptName is "Hulu" then
				set searchPreString to "https://www.google.com/webhp?client=safari&rls=en&ie=UTF-8&oe=UTF-8#q=hulu.com:"
				set searchPostString to ""
				set searchURL to searchPreString & searchString & searchPostString
				tell application "Safari" to open location searchURL
				
			else if scriptName is "Wiki" then
				
				set AppleScript's text item delimiters to {"_"}
				set searchString to (words of clipBoardString) as text
				set searchPreString to "https://en.wikipedia.org/wiki/"
				set searchPostString to ""
				set searchURL to searchPreString & searchString & searchPostString
				tell application "Safari" to open location searchURL
			else if word 1 of scriptName is "TOL" then
				
				set whichTOL to word 2 of scriptName
				
				SearchTOL(whichTOL, clipBoardString, {"", ""})
				--		"TOL Headlines", "TOL Byline", "TOL Words in Story", "TOL Names and Phrases",				
				
			end if
		end if
	end repeat
	
	tell application "Safari" to activate
	tell me to activate
end RunTheScript


on OpenTOLTab()
	tell application "Safari"
		activate
		set searchDocument to make new document at beginning with properties {URL:tolPage}
		set searchTab to current tab of window 1
	end tell
	delay 1
	return searchTab
end OpenTOLTab

on SearchTOL(searchWhere, searchFor, searchRange)
	tell application "Safari" to activate
	OpenTOLTab()
	tell application "System Events"
		tell process "Safari"
			activate
			delay 1
			set {startDate, endDate} to {"", ""}
			set searchDate to ""
			
			if searchWhere is "Words" then
				set value of text field 1 of UI element 1 of row 1 of table 1 of UI element 1 of scroll area 2 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window 1 to searchFor
			else if searchWhere is "Names" then
				set value of text field 1 of UI element 1 of row 2 of table 1 of UI element 1 of scroll area 2 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window "TimesOnline" to searchFor
			else if searchWhere is "Headlines" then
				set value of text field 1 of UI element 1 of row 3 of table 1 of UI element 1 of scroll area 2 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window "TimesOnline" to searchFor
			else if searchWhere is "Byline" then
				set value of text field 1 of UI element 1 of row 4 of table 1 of UI element 1 of scroll area 2 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window "TimesOnline" to searchFor
			end if
			
			click button "Search TimesOnline" of group 5 of UI element 1 of scroll area 2 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window "TimesOnline"
			
		end tell
	end tell
	
	
end SearchTOL

on ParseIMDBCast(searchString)
	
	set myCast to paragraphs of searchString
	set AppleScript's text item delimiters to {" ("}
	
	repeat count of myCast times
		if "..." is not in item 1 of myCast then
			set myCast to the rest of myCast
		else
			exit repeat
		end if
	end repeat
	
	set AppleScript's text item delimiters to {return}
	set myCast to myCast as text
	
	set AppleScript's text item delimiters to {tab & "..." & tab & return}
	set myCast to text items of myCast
	set AppleScript's text item delimiters to {tab}
	set myCast to myCast as text
	
	set myCast to paragraphs of myCast
	local actorsTable
	set actorsTable to {}
	repeat with thisActorCharactor in myCast
		set AppleScript's text item delimiters to {tab, " / ...", " ("}
		
		set actorName to text item 2 of thisActorCharactor
		set characterName to text item 4 of thisActorCharactor
		
		set firstName to (word 1 of characterName)
		
		if firstName is in {"The", "Mr", "Mrs", "Dr", "Doctor", "Officer", "Det", "Captain"} then set firstName to characterName
		set AppleScript's text item delimiters to {" Episodes, ", " Episode, "}
		set firstNameList to text items of firstName
		if the (count of firstNameList) > 1 then
			set nameList to words of item 1 of firstNameList
			set firstName to items 1 thru -2 of nameList
			
			set AppleScript's text item delimiters to {" "}
			set firstName to firstName as text
		end if
		set listingReference to firstName & " (" & actorName & ") "
		set the end of actorsTable to {false, actorName, characterName, firstName, listingReference, ""}
	end repeat
	
	
	set {xC, yC} to {100, 100}
	
	set tableTitle to "Actors, Characters"
	set tablePrompt to "Select which cast members to reference"
	set multipleSelectionsAllowed to true
	set canAddAndDelete to true
	set columnHeadings to {"Group", "Actors", "Characters", "First Names", "References", "Reference Lists"}
	set rowNumbering to false
	set emptySelectionAllowed to false
	set editableColumns to {}
	--set rowTemplate to  row 1 of actorsTable
	
	repeat
		set tableData to make new table with data actorsTable ¬
			with title tableTitle ¬
			with prompt tablePrompt ¬
			multiple selections allowed multipleSelectionsAllowed ¬
			can add and delete canAddAndDelete ¬
			column headings columnHeadings ¬
			row numbering rowNumbering ¬
			editable columns editableColumns ¬
			empty selection allowed emptySelectionAllowed
		
		set OKButton to "Continue"
		set extraButton to "Refresh"
		
		
		
		modify table tableData ¬
			OK button name OKButton ¬
			OK button is default false ¬
			extra button name extraButton ¬
			highlighted rows {} ¬
			row dragging true ¬
			column reordering false ¬
			initial position {xC, yC}
		
		set userChoices to display table tableData ¬
			with extended results
		set whichButton to button number of userChoices
		userChoices
		set {xC, yC, wd, ht} to final position of userChoices
		if rows selected of userChoices is {} then
			set tablePrompt to "No rows selected" & return & return & "Select which cast members to reference"
		else
			set tablePrompt to "Select which cast members to reference"
			
			set groupedNames to {}
			set selectedNames to {}
			repeat with thisName in values selected of userChoices
				if item 1 of thisName is true and item 3 of thisName is not "" then
					set the end of groupedNames to thisName as item
				else
					set the end of selectedNames to thisName as item
				end if
			end repeat
			set numberOfGroupedNames to the count of groupedNames
			set newGroupChars to {}
			set newGroupNames to {}
			set newTableData to {}
			
			if numberOfGroupedNames > 1 then
				repeat with x from 1 to numberOfGroupedNames
					set the end of newGroupChars to item 4 of item x of groupedNames
					set the end of newGroupNames to item 2 of item x of groupedNames
				end repeat
				if numberOfGroupedNames is 2 then
					set AppleScript's text item delimiters to {" and "}
					
					set GroupChars to newGroupChars as text
					set AppleScript's text item delimiters to {", "}
					set newGroupNames to newGroupNames as text
					set GroupNames to newGroupNames
				else
					set AppleScript's text item delimiters to {", "}
					set GroupChars to items 1 thru -2 of newGroupChars as text
					set GroupChars to GroupChars & " and " & (the last item of newGroupChars as text)
					
					set GroupNames to items 1 thru -2 of newGroupNames as text
					set GroupNames to GroupNames & " and " & (the last item of newGroupNames as text)
				end if
				set groupedInfo to GroupChars & " (" & GroupNames & ")"
				set the end of newTableData to {false, GroupNames, "", GroupChars, groupedInfo, ""}
				
			end if
			-- {false, actorName, characterName, firstName, listingReference, ""}
			
			set newTableData to newTableData & selectedNames
			set actorsTable to newTableData
			if whichButton is 1 then exit repeat
		end if
		
	end repeat
	set referenceString to {}
	repeat with thisReference in actorsTable
		set the end of referenceString to item 5 of thisReference
	end repeat
	set AppleScript's text item delimiters to {return}
	
	set referenceString to referenceString as text
	--DialogCopyOrTextWrangler
	
	set dialogAnswerText to referenceString
	set dialogPrompt to "References to Cast and Characters: " & return & referenceString
	set dialogTitle to "Cast and Character references"
	set dialogAnswerText to FindChange(dialogAnswerText, "  ", " ")
	DialogCopyOrTextWrangler(dialogAnswerText, dialogPrompt, ¬
		dialogTitle)
end ParseIMDBCast

on DialogCopyOrTextWrangler(dialogAnswerText, dialogPrompt, ¬
	dialogTitle)
	set buttonsList to {"Cancel", "Copy", "TextWrangler"}
	set userchoice to display dialog dialogPrompt ¬
		default answer dialogAnswerText ¬
		buttons buttonsList ¬
		default button 2 ¬
		with title dialogTitle ¬
		giving up after 90
	if gave up of userchoice then return {"", ""}
	set whichButton to button returned of userchoice
	set userAnswerText to text returned of userchoice
	
	if whichButton is "TextWrangler" then
		tell application "TextWrangler"
			make new window at beginning
			set text of window 1 to userAnswerText
			activate
		end tell
	else if whichButton is "Copy" then
		tell application "Finder"
			set the clipboard to userAnswerText
		end tell
	end if
	return {whichButton, userAnswerText}
end DialogCopyOrTextWrangler

on FindChange(textToSearch, textToFind, textToReplace)
	set saveTID to AppleScript's text item delimiters
	set AppleScript's text item delimiters to textToFind
	set textToSearch to every text item of textToSearch
	set AppleScript's text item delimiters to textToReplace
	set textToSearch to textToSearch as string
	set AppleScript's text item delimiters to saveTID
	return textToSearch
end FindChange

Same behavior with an Enhanced applet. The crash is an AppName “quit unexpectedly.”

“Click Reopen to open the application again…”

It seems the first time I try to run the applet it delays before crashing, then after that it crashes right away.

I had to comment out the reference to your List lib, but it seems to work as an applet just fine here.

On my side, it works but I found an odd “feature”.
If I search for the string |⌘|,
selecting Google generates the link : https://www.google.com/search?q=|+⌘+|&cad=h which behaves well.
If I select Wiki, it generates the link : https://en.wikipedia.org/wiki/|_⌘_| and I get the warning :
The requested page title contains unsupported characters: “|”.
Return to Main Page.