Script Editor: making script files Run-Only, programatically

I wrote this code following the Compile an application with ScriptEditor by AppleScript ?!? topic. The link is provided to compare changes I made.

An interesting idea was implemented there, which more or less works. But there are a number of shortcomings that I decided to eliminate, for myself (and other users).

You can use following script as droplet as well.

.


-- Script: makes a Run_Only app from a .scpt file(s) or a Not Run Only bundle app(s)

set these_items to choose file of type {"com.apple.applescript.script", "com.apple.application-bundle"} with prompt "Select Applescript File(s) to make Run_Only" with multiple selections allowed
my process_item(these_items)

on open these_items
	process_item(these_items)
end open


------------------------------------------------------  HANDLERS  ------------------------------------------------------

on process_item(these_items)
	repeat with anItem in these_items
		set anItem to contents of anItem
		try -- checks if the file is Run_Only already
			((anItem as text) & "Contents:Resources:Scripts:main.recover.rtf") as alias
			tell application "System Events" to set typeID to type identifier of file (anItem as text)
			set {documentName, targetMix} to my script_item(anItem)
			if typeID is "com.apple.application-bundle" then my pack_item(anItem, documentName, targetMix)
		on error number -1700 -- the file is Run_Only already
			display dialog "" & anItem & "
 
is  Run_Only already !!!

So, don't try to make it Run_Only again." giving up after 5
		end try
	end repeat
end process_item

on script_item(this_item)
	set documentName to my getBaseName(POSIX path of this_item)
	set targetMix to ((path to desktop as text) & documentName & ".app")
	tell application "Script Editor"
		open this_item
		save document 1 in targetMix as "application bundle" with run only
		close document 1
	end tell
	return {documentName, targetMix}
end script_item

on pack_item(this_item, documentName, targetMix)
	try -- Duplicate file droplet.icns
		set SetFileor to ((this_item as text) & "Contents:Resources:droplet.icns")
		set SetFileds to targetMix & ":Contents:Resources:" as alias
		my duplicate_routine(SetFileor, SetFileds)
	on error -- Duplicate file applet.icns
		set SetFileor to ((this_item as text) & "Contents:Resources:applet.icns")
		set SetFileds to targetMix & ":Contents:Resources:" as alias
		my duplicate_routine(SetFileor, SetFileds)
	end try
	-- Duplicate file Info.plist
	set SetFileor to ((this_item as text) & "Contents:Info.plist")
	set SetFileds to targetMix & ":Contents:" as alias
	my duplicate_routine(SetFileor, SetFileds)
end pack_item

on duplicate_routine(SetFileor, SetFileds)
	tell application "Finder" to duplicate document file SetFileor to SetFileds with replacing
end duplicate_routine

on getBaseName(posixPath)
	set {ATID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "/"}
	if (posixPath ends with "/") then
		set baseName to text item -2 of posixPath
	else
		set baseName to text item -1 of posixPath
	end if
	if (baseName contains ".") then
		set AppleScript's text item delimiters to "."
		set baseName to text 1 thru text item -2 of baseName
	end if
	set AppleScript's text item delimiters to ATID
	return baseName
end getBaseName