• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Load Script
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Load Script
      • From: Luther Fuller <email@hidden>
References: 
 >Load Script (From: Luther Fuller <email@hidden>)
 >Re: Load Script (From: Stan Cleveland <email@hidden>)
 >Re: Load Script (From: Luther Fuller <email@hidden>)
 >Re: Load Script (From: Alex Zavatone <email@hidden>)
 >Re: Load Script (From: Luther Fuller <email@hidden>)

  • Prev by Date: Re: Load Script
  • Next by Date: Re: Load Script
  • Previous by thread: Re: Load Script
  • Next by thread: Re: Load Script
  • Index(es):
    • Date
    • Thread