Re: Save a NSAppleScript to a file
Re: Save a NSAppleScript to a file
- Subject: Re: Save a NSAppleScript to a file
- From: p3consulting <email@hidden>
- Date: Sun, 23 Nov 2003 19:57:35 +0100
>
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.