Re: Reusability / inclusion of Apple Scripts?
Re: Reusability / inclusion of Apple Scripts?
- Subject: Re: Reusability / inclusion of Apple Scripts?
- From: Michael Grant <email@hidden>
- Date: Wed, 12 May 2004 17:43:11 -0500
On May 12, 2004, at 3:08 PM, Cliff Pruitt wrote:
Hey thanks for the great info! Can I follow up & ask, what exactly is
happening & is 'script_file' a reserved AppleScript variable or object
or something (sorry, I still get my vocab mixed up).
No, just the name of the variable set in the loadScript(theScript)
handler.
Maybe I should have simplified the script a little before posting it to
the list. The complication in the handler comes from having it look in
both the user Library folder and the "local" Library folder for the
archive script, and even giving the user a chance to choose it if it
happens to be somewhere else. The property 'archiveScript' in this case
specifies the actual script I want to load and its immediate parent
folder, which I have installed in one of the Library folders. I could
have just specified a full path to the library script to simplify
things. There's no particular place that library scripts need to be
located.
Also does this RUN the referenced script or load it into the current
script.
The handler loads the library script and returns it as a script object.
The line 'set archive_script to loadScript(archiveScript)' is what
calls the handler and assigns a name to the script object it returns.
Then the line 'tell archive_script to archiveItem(archiveNameRoot,
originalSpec, backupSpec, timeoutLength, keepArchives)' is what
actually runs the script object, passing it those parameters (whose
values are defined in the script properties).
For example if Script_B is just a bunch of subroutines or Script
Object definitions, and if I load Script_B into Script_A, does
Script_A have access to those subroutines, or is Script_A just sending
system messages to tell Script_B to run.
Script_A actually loads Script_B into its own memory space. It's also
possible to use the 'run script' syntax to run an external script
directly without first loading it.
Can Script_A load Script_B, and also load Script_C, Script_D, and
Script_E?
Yes.
You should definitely get the Neuburg book I recommended this morning.
It goes into all of this in great detail.
Thanks a lot. I've been enjoying AS this week. Its been nice to make
some headway. ;-)
Happy scripting!
Michael
- Cliff
On May 12, 2004, at 1:15 PM, Michael Grant <email@hidden> wrote
--__--__--
Message: 7
From: Michael Grant <email@hidden>
Subject: Re: Reusability / inclusion of Apple Scripts?
Date: Wed, 12 May 2004 09:59:48 -0500
To: AppleScript-Users list <email@hidden>
On May 12, 2004, at 9:03 AM, Cliff Pruitt wrote:
If I write Apple scripts (not in AS Studio), and want to use
something
like a script object, does the script that is running have to contain
the object definition inside of that script, or is it possible to
create "libraries" and include them in the running script like you
can
in OOP languages. If so does the other "library" script have to be
open and running in order to be accessed? Does the "library" script
have to be saved as an application?
I guess my real question is how, if there is a way at all, do you
guys
work with multiple scripts or script objects outside of AS Studio?
How do you reference them?
Below is a script that runs every night to back up certain files on my
system. I have a couple dozen copies of the script differing only in
the properties at the start; they all call the same library script
that
does the actual compression and backup routine according to the
parameters passed to it. (One of these days maybe I'll consolidate
them
into a single |berscript that just reads the parameters from a text
file. I suppose I should update "Finder" to "System Events" too....)
As you can see by the code, a script can load external library scripts
stored elsewhere on the system. The library scripts don't need to be
saved as applications.
I have very little experience with Studio, so I'll leave that part to
others.
Michael
property archiveScript : "BDScriptLibrary:Archive.scpt"
property archiveNameRoot : "ToDo"
property originalSpec : "Budapest:Users:mgrant:Documents:to do:"
property backupSpec : "Bratislava:Backups:To Do Backups:"
property timeoutLength : 390
property keepArchives : 2
set archive_script to loadScript(archiveScript)
tell archive_script to archiveItem(archiveNameRoot, originalSpec,
backupSpec, timeoutLength, keepArchives)
on loadScript(theScript)
try
tell application "Finder" to set script_file to ,
(((path to home folder) as string) & "Library:" & theScript) as
alias
on error
try
tell application "Finder" to set script_file to ,
((name of startup disk) & ":Library:" & theScript) as alias
on error
try
set script_file to (choose file with prompt ("Where is the library
script " & theScript & "?"))
on error
display dialog "Sorry, master script not found!"
return
end try
end try
end try
return (load script script_file)
end loadScript
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.
--
"Open the pod bay doors, Hal."
"I'm sorry, Dave. I'm afraid I can't do that."
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.