Generating an Applescript program from Applescript itself

I want to create an Applescript program from an Applescript program.

In a PC environment it would like creating a bat file from a program. Is this possible within an Apple environment?

Thanks!
Daniel

Look up ‘load script’, ‘store script’ & ‘run script’ part of the Standard Additions dictionary.

You could use osacompile…

set a to "tell application \"Finder\""
set b to "reveal (path to documents folder)"
set c to "activate"
set d to "end tell"
set outPath to (path to desktop folder as text) & "something.scptd"

do shell script "/usr/bin/osacompile -e " & quoted form of a & " -e " & quoted form of b & " -e " & quoted form of c & " -e " & quoted form of d & " -o " & quoted form of POSIX path of outPath

However, I like Mark67’s suggestion better… I didn’t know the “store script” command.

set outPath to (path to desktop folder as text) & "something.scptd"
script o
	tell application "Finder"
		reveal (path to documents folder)
		activate
	end tell
end script

store script o in file outPath
set outPath to (path to desktop folder as text) & "something.app"

Also appears to work but I think you need ‘osacompile’ for the other options?

I do like that our applescript files’s file creator is ‘ToyS’ that makes me :slight_smile:

Hello.

Take a close look at this post : Here.
It describes the way to go with an example that are easy to customize.

Yes, osacompile does have more options like “-x Save the resulting script as execute-only”.

FYI, (Apple)Script Editor’s code name was Toy Surprise, hence the ToyS.

All these years and I never knew that! :lol:

Hello.

While we are enlightened with historical facts I found it appropriate to post this link to the history of AppleScript via DaringFireball.net