Script to change a Script (.scpt) in to an Application (.app)?

I say it seems to work, not in my case with some (I think older scripts) scripts.


Since manually saving the original as an application from Script Editor works, I think that manually copying, pasting, and saving it is certain to also work and serves no diagnostic purpose here. That is to say, since saving manually already works but the script saved files don’t, I don’t think further tests involving manual saves are likely to shed light on the cause.

I suggest we just go ahead and make a copy-paste (or similar) alternate version for him to try.

I can do that later if nobody else gets to it first.

very kind indeed t.spoon. thank you for helping here.

Please try this

set sourceFolder to choose folder

set p2D to path to desktop as text # Edit to fit your needs
set theDest to "applis" # Edit to fit your needs
set destFolder to p2D & theDest & ":"

tell application "System Events"
	if not (exists folder destFolder) then
		make new folder at folder p2D with properties {name:theDest}
	end if
	set theScripts to (disk items of sourceFolder whose name extension is "scpt")
	repeat with aScript in theScripts
		set destName to text 1 thru -6 of (get name of aScript) & ".app"
		set destPath to destFolder & destName
		my exportAsApplication(aScript, destPath)
	end repeat
end tell

on exportAsApplication(aFile, destPath)
	tell application "Finder"
		set aFile to aFile as alias
	end tell
	tell application "Script Editor"
		open aFile
		tell document 1
			set scriptContents to the contents
			close saving no
		end tell
		set newDoc to make new document
		delay 1
		tell document 1
			set the contents to scriptContents
			save as "application" in file destPath
		end tell
	end tell
end exportAsApplication

Morning t.spoon, thanks.

The script translates to a app. but the app does not work.

I thought of a workaround for it now. I duplicate the original script. Run that though your latest script and now almost all of them work.

Strange, or?

Thanks everybody for your help! much appreciated!

This must go on the all-time “weird” bugs list. Copying and pasting it into a new script and saving does work when you do it by hand, but not when it’s automated. And either works for new scripts, the automation only fails when it’s an old script.

I feel like if this were solved, it could be added to this list:

I think about it.