Re: Dynamic creation of an AppleScript via AppleScript


Christopher Stone
 

On 09/03/2018, at 09:24, Markus Ruggiero <mailinglists@...> wrote:
I want to create an AppleScript .scpt file programmatically without using Script Editor.


Hey Markus,

Have a look at these two post on the Applescript Users List.

--
Best Regards,
Chris
use framework "Foundation"
use framework "OSAKit"

set sourceURL to current application's class "NSURL"'s fileURLWithPath:"path/to/file.applescript"
set destURL to current application's class "NSURL"'s fileURLWithPath:"path/to/file.scpt"
set theScript to current application's OSAScript's alloc()'s initWithContentsOfURL:sourceURL
set theResult to theScript's compileAndReturnError:(missing value)
if theResult as boolean then
theScript's writeToURL:destURL ofType:(current application's OSAStorageScriptType|error|:(missing value)
end if




osacompile -o <object-file> <source-file>  (see the man page)



Join applescript@apple-dev.groups.io to automatically receive all group messages.