Re: Save a NSAppleScript to a file
Re: Save a NSAppleScript to a file
- Subject: Re: Save a NSAppleScript to a file
- From: Lorenzo <email@hidden>
- Date: Sun, 23 Nov 2003 22:46:02 +0100
Pascal,
you are so kind, but the problem is that I am letting the users write their
own short AppleScript in my applications, just to be executed at launch and
before quit. So they could write whatever in the AS string code.
It's not something like a fixed string code. It could vary all the time.
It could be "tell application" or "mount volume" or a very complex script.
So I think the best is to compile the AS when the user, after he wrote the
AS text, presses the button Apply, then if there are no errors I save the
compiled script somehow, then when the user later launchs the app, my app
executes the compiled AppleScript. The problem is that I cannot save the
compiled AppleScript. I would need something like
*as = [[NSAppleScript alloc] initWithSource:asText];
ok = [*as compileAndReturnError:nil];
if(!ok) return;
NSData *asData = [NSData dataWithNSAppleScript:as];
[asData writeToFile:filePath atomically:NO];
But as you know the API dataWithNSAppleScript doesn't exist.
I think there should be a way to convert a NSAppleScript to a NSData or to a
simple pointer, but I don't know how.
Best Regards
--
Lorenzo
email: email@hidden
>
From: p3consulting <email@hidden>
>
Date: Sun, 23 Nov 2003 19:57:35 +0100
>
To: Cocoa Forum <email@hidden>
>
Cc: Lorenzo <email@hidden>
>
Subject: Re: Save a NSAppleScript to a file
>
>
> Hi,
>
> thank you. I have to save the AS already compiled, because...
>
> Let's imagine the following:
>
>
>
> Your AS source string contains
>
> tell application "Entourake"...
>
> instead of
>
> tell application "Microsoft Entourage"
>
>
>
> so at the moment my applications compile that, the user is asked to
>
> locate
>
> the application "Entourake". The user locates the application
>
> "Microsoft
>
> Entourage" and this information will be stored in the compiled AS.
>
> I want to save this AS already compiled.
>
> If I stored the AS source code string, the user would be asked to
>
> locate the
>
> application "Microsoft Entourage" any time my application compiles and
>
> runs
>
> the AS. And this is boring. So at least, I would like to be able to
>
> fix the
>
> original source code string... how?
>
>
>
>
>
>
>
Carbon has specific calls to find an application based on its creator
>
type (PBCatSearch family among others...),
>
and Cocoa's NSWorkSpace has some too
>
(absolutePathForAppBundleWithIdentifier, fullPathForApplication)
>
so you could keep in your app preferences the name the Entourage on the
>
current user config.
>
>
At startup:
>
>
EntouragePathname = nil
>
if prefs exist then
>
take entouragepath from prefs
>
check if file still exist at saved path
>
if yes then
>
EntouragePathname = savepathName
>
end if
>
end if
>
>
if EntouragePathname = nil then
>
look for Entourage
>
if none or more than one found then
>
ask user what to do
>
if user chooses to cancel then
>
either quit either disable functionality (depends on your
>
needs/specifications)
>
end if
>
EntouragePathname = what the user chooses (must be valid)
>
else
>
EntouragePathname = the one we found
>
endif
>
endif
>
>
save EntouragePathname to prefs
>
>
Then prepare the scripts replacing variable in script file(s) by
>
EntouragePathname
>
>
source code of scrips could be something like
>
tell application "<<ENTOURAGE_APP_NAME>>"
>
...
>
end tell
>
>
initializing the script by reading its "template" from some resource in
>
your bundle into a NSMutableString and
>
then something like
>
[templateScriptString
>
replaceOccurrencesOfString:@"<<ENTOURAGE_APP_NAME>>" withString:
>
EntouragePathname options:0 range:NSMakeRange(0,[templateScriptString
>
length])];
>
>
that way you should disturb user only at first startup or if Entourage
>
has moved, has been renamed, etc.
>
>
>
>
Pascal Pochet
>
P3 Consulting
>
email@hidden
>
http://www.p3-consulting.net
_______________________________________________
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.