I’m trying to figure out some details about the public, but undocumented, OSAKit framework, which I’m trying to use from within an AppleScript script (!). I can initialize, compile and write a script to disk, using code similar to the following:
use framework "Foundation"
use framework "OSAKit"
use scripting additions
-- Path to the script we're going to create
set output to current application's NSURL's fileURLWithPath:((POSIX path of (path to desktop)) & "/test.scpt")
-- LibBundle.scptd is an existing script bundle containing only a script library called 'Lib', which we are going to use in our script
set someLib to current application's NSURL's fileURLWithPath:((POSIX path of (path to desktop)) & "/LibBundle.scptd")
set lang to current application's OSALanguage's defaultLanguage()'s sharedLanguageInstance()
set theScript to current application's OSAScript's alloc's ¬
initWithSource:"use script \"Lib\"" fromURL:someLib languageInstance:lang usingStorageOptions:(current application's OSANull)
-- Not using this, it's here just as an example:
set {theData, theError} to theScript's compiledDataForType:"osas" usingStorageOptions:(current application's OSANull) |error|:(reference)
set {didSucceed, theError} to theScript's ¬
writeToURL:output ofType:"osas" usingStorageOptions:(current application's OSANull) |error|:(reference)
if not didSucceed then
return theError as list
end if
"OK"
First problem: the icon of the resulting script is not the usual script icon (it looks more like a generic document’s icon). Why?
Second: what are the legitimate values for the compiledDataForType and ofType parameters? I have used “osas”, but, in fact, using other strings does not seem to make any difference (possibly because the ones I’ve tried are all wrong, which might explain the icon problem, too).
Third: it seems to me that I should be able to use OSAKit to create an applet (since OSAScript.h has constants like OSAStayOpenApplet to be used when writing), and maybe also a script bundle. But I cannot figure out how to do that. Do you have any idea?
Finally, Script Editor doesn’t let me save the script.