Applescript write script within a script

I am trying to figure out how to write a script file within my applescript program and then save it to the hard drive.

For example:

Within applescript studio I have:

script theScript
display dialog “Hello”
end theScript

store script theScript in file (some arbitrary file) with replacing

When I try to run the script that it creates it is run-only and nothing happens. It doesn’t run; I am not even sure if there is any code inside the new file. Can anyone tell me what I am doing wrong?

Thanks,
joshabb

Sounds like what you need to do is use do shell script to issue an osacompile command. Check the man page for osacompile in the Terminal and you’ll see what I’m talking about. osacompile will let you compile a script file into a working script.