Re: Run and AppleScript from within and AppleScript
Re: Run and AppleScript from within and AppleScript
- Subject: Re: Run and AppleScript from within and AppleScript
- From: email@hidden
- Date: Thu, 5 Dec 2002 20:54:23 -0500
On Thu, 05 Dec 2002 15:09:33 +1100,
The Other Rob <email@hidden> asked,
>
I've trying all afternoon to work out how to get an
>
AppleScript to run another AppleScript. Do I have
>
to create a script application and run that?
>
Or can I directly run the script on it's own?
There are two ways you can do this:
1. Save the second AppleScript as a script applications.
Make sure it is saved as "Stay Open". You'll probably
want to turn off the script's startup display as well.
2. Load the second AppleScript as a script object.
Application Example.
-- "Script 2" --
on somehandler(argument)
-- do something useful.
return "You told Script 2 " & argument
end somehandler
-- Calling Script --
tell application "Script 2" to somehandler("Hello")
display dialog result
-- display: "You told Script 2 Hello"
Script Object example (using the same "Script 2")
set Script2 to (load script "Script 2")
tell Script2 to somehandler("Hello")
display dialog result
-- display: "You told Script 2 Hello"
Which to use? The Script Object is great for library
subroutines, while the Application approach is like a server.
The Script Object belongs to the script that loads it, and
each script that loads the script object gets its own copy. The
Application script is shared among all scripts that call it.
That may be what you want, or may be a problem.
Sending a message to another application is a whole lot
slower than sending one to a script object.
If your Script Object is a battle-hardened, proven, stable chunk of code, you
can load it when the script is compiled, which makes the calling script run
faster:
property Script2: load script "Script2"
tell Script2 to somehandler("Hello")
display dialog result
-- display: "You told Script 2 Hello"
--
Scott Norton Phone: +1-703-299-1656
DTI Associates, Inc. Fax: +1-703-706-0476
2920 South Glebe Road Internet: email@hidden
Arlington, VA 22206-2768 or email@hidden
_______________________________________________
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.