• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Save a NSAppleScript to a file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Save a NSAppleScript to a file


  • Subject: Re: Save a NSAppleScript to a file
  • From: Mark Lilback <email@hidden>
  • Date: Sun, 23 Nov 2003 19:22:48 -0800 (PST)

If your application requires Panther, you can use OSAStoreFile which
can save in any of the standard AppleScript file formats (including
as a bundle).

Otherwise, you've got to make a few OSA calls. Here is a category
that adds -writeToFile: to NSAppleScript, which saves the compiled script
(with the source code recoverable by OSA calls).

@implementation NSAppleScript(RTExtensions)
//writes out as a data-fork compiled script that should have the
// extension ".scpt"
-(BOOL)writeToFile:(NSString*)path
{
OSStatus err;
ComponentInstance defComponent, asComponent;
OSAID scriptId=kOSANullScript;
BOOL success = NO;

NSAppleEventDescriptor *compiledDesc =
[NSAppleEventDescriptor nullDescriptor];
NSAppleEventDescriptor *srcDesc =
[NSAppleEventDescriptor descriptorWithString: [self source]];

defComponent = OpenDefaultComponent(kOSAComponentType, 'scpt');
if (nil == defComponent)
return NO;
err = OSAGetScriptingComponent(defComponent, kAppleScriptSubtype,
&asComponent);
if (noErr != err) {
CloseComponent(defComponent);
return NO;
}
err = OSACompile(asComponent, (AEDesc*)[srcDesc aeDesc],
kOSAModeCompileIntoContext, &scriptId);
if (noErr == err) {
err = OSAStore(asComponent, scriptId, typeOSAGenericStorage,
kOSAModeNull, (AEDesc*)[compiledDesc aeDesc]);
if (noErr == err)
success = [[compiledDesc data] writeToFile: path
atomically: NO];
}

CloseComponent(defComponent);

return success;
}
@end


__________________________________________________________________________
"They that can give up essential liberty
Mark J. Lilback to obtain a little temporary safety
<email@hidden> deserve neither liberty or safety."
http://www.lilback.com/ -- Benjamin Franklin
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: Allow only one program to be running
  • Next by Date: screen capture notification?
  • Previous by thread: Re: Save a NSAppleScript to a file
  • Next by thread: Re: Save a NSAppleScript to a file
  • Index(es):
    • Date
    • Thread