Re: Load Script
Re: Load Script
- Subject: Re: Load Script
- From: Ron Hunsinger <email@hidden>
- Date: Wed, 25 May 2011 18:11:04 -0700
On May 25, 2011, at 3:42 PM, Luther Fuller wrote: The MAIN script contains ...
property pathToHelp : "Contents:Resources:Disk Image Tools Help.pdf"
The called script contains ...
on run try
display dialog pathToHelp --**************
which errors because pathToHelp is an undefined variable.
The problem you're running into is that when you use "load script", the loaded script's parent isn't set to the script doing the loading, and the parent cannot be changed once initialized.
One solution is to insert the main script into the loaded script, and use explicit qualification. I'll give an example where the loaded script needs access to a property and a handler from the loader.
The MAIN script contains ...
property someText : "This is some text"
on warble() return "Sing a song" end warble
set B to load script (alias ... ) set commons of B to me run B
The called script contains ...
property commons : missing value
display dialog warble() of commons display dialog someText of commons
(If you find it more readable, commons can be defined as a script with an empty body. It doesn't matter; it'll be replaced before being used.)
If you don't like sprinkling the called script with "of commons" and/or "commons's", you can have the script initialize its parent property to link back to the MAIN script:
The Main script contains ...
property someText : "This is some text"
on warble() return "Sing a song" end warble
set B to load script (alias ((path to home folder as text) & "Junk_:scripts:B.scpt")) set B to B's linkedup(me) run B
The called script contains ...
on linkedup(caller) script BB property parent : caller global someText
display dialog warble() display dialog someText end script BB end linkedup
I second the recommendation for Matt Neuberg's "AppleScript: The Definitive Guide". It's a real eye-opener.
|
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden