Batch convert .scpt files to .app files?

Haven’t used Applescript alot, but I have a PHP script that generates a bunch of applescript files dynamically. I have to open them in Script Editor though and save them as applications to make them executable. Is there a way I can do this as a batch - there are over 1 hundred. FYI - The purpose is a Flash projector file that, via Actionscript, runs an fscommand that executes an applescript.

Thanks!

Applescript Studio?

You can script Script Editor to do just that.

Bruce,

Thanks so much ” can you get me started? Thanks in advance…

Here’s something to get you started.

set _script to "display dialog \"Hello World.\""
set _deskPath to path to desktop as Unicode text
set _savePath to _deskPath & "script.app"

tell application "Script Editor"
	activate
	set _doc to make new document with properties {contents:_script}
	save _doc as "application" in _savePath
	close front document
end tell

Hi,

an alternative way is with the shell command osacompile,
which can compile simple text files, e.g

do shell script "osacompile -o " & quoted form of POSIX_scpt & space & quoted form of POSIX_txt

POSIX_txt is the source text file (as POSIX path)
POSIX_scpt is the destination file (as POSIX path)

Does the -o option compile it as an applet in Tiger?

gl,

Hi kel,

from the osacompile man page:

If the -o option is specified and the file does not already exist,
osacompile uses the filename extension to determine what type of file to
create. If the filename ends with .app'', a bundled applet or droplet will be created. If the filename ends with .scptd’', a bundled com-
piled script will be created. Otherwise, the resulting script will be
placed in the resource fork and/or data fork of the output file depending
upon what other options are specified.

HI.

If the “.scpt” files really are compiled applescripts, you could use a combination of ‘load script’ and ‘store script’. The latter saves as an application if the save name has an “.app” extension (in Tiger, at least):

on scptToApp(scptFile) -- scptFile is assumed to be an alias to a compiled script file with a ".scpt" name extension.
	set scptPath to scptFile as Unicode text
	set astid to AppleScript's text item delimiters
	set AppleScript's text item delimiters to "."
	set appPath to text 1 thru text item -2 of scptPath & ".app"
	set AppleScript's text item delimiters to astid
	
	set compiledScript to (load script scptFile)
	store script compiledScript in file appPath

	return appPath as alias
end scptToApp

scptToApp(choose file)

To create compiled script files or applets from text files, a combination of ‘read’, ‘run script’, and ‘store script’ appears to be quite a bit faster than “osacompile”:

on textToScript(textFile, extn) -- extn should be ".scpt" or ".app"
	set tfPath to textFile as Unicode text
	set scriptFile to false
	if (tfPath ends with ".applescript") or (tfPath ends with ".txt") then
		try
			-- Create a script object from the text in the file.
			set compiledScript to (run script ("script" & return & (read textFile) & return & "end script"))
			
			set astid to AppleScript's text item delimiters
			set AppleScript's text item delimiters to "."
			set sfPath to text 1 thru text item -2 of tfPath & extn
			set AppleScript's text item delimiters to astid
			
			store script compiledScript in file sfPath
			set scriptFile to sfPath as alias
		end try
	end if
	
	return scriptFile
end textToScript

textToScript(choose file, ".app")

How would you make this a droplet that allowed you to choose the output folder? I’ll keep searching and see what I can put together.

I assume by “this” you mean the script-to-applet script.

on scptToApp(scptPath, fldrPath) -- scptPath is assumed to be the path to a compiled script file with a ".scpt" name extension.
	set astid to AppleScript's text item delimiters
	set AppleScript's text item delimiters to ":"
	set appPath to fldrPath & (text 1 thru -6 of text item -1 of scptPath) & ".app"
	set AppleScript's text item delimiters to astid
	
	set compiledScript to (load script file scptPath)
	store script compiledScript in file appPath
end scptToApp

on open theseItems
	set fldrPath to (choose folder with prompt "Where do you want to store the applet files?") as Unicode text
	repeat with thisItem in theseItems
		set thisPath to thisItem as Unicode text
		if (thisPath ends with ".scpt") then scptToApp(thisPath, fldrPath)
	end repeat
end open

Yes that is what I meant, and thank you very much, I will be using your script quite often!
Thanks for the Christmas gift :smiley: