• 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: Calling handlers in other scripts inside AS application
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Calling handlers in other scripts inside AS application


  • Subject: Re: Calling handlers in other scripts inside AS application
  • From: Paul Berkowitz <email@hidden>
  • Date: Thu, 24 Mar 2005 10:51:04 -0800

Title: Re: Calling handlers in other scripts inside AS application
On 3/24/05 10:26 AM, "Thomas Berry" <email@hidden> wrote:


Thanks for your response.  As you probably guessed, I'm very new to programming my Mac but I'm trying the best that I can.  I appreciate your help.  

This is a Studio application to build a front end to allow use of the Mac in a car for music, DVD, photos, etc.  I am using XCODE to build the Applescript application.  As far as I know, this "is" Applescript studio.

Your hints have helped me.  I needed to be dealing with the compiled scripts.  I was confused because XCODE gives the name of the scripts as "ScripA.applescript".  So I was targeting the uncompiled file.  Since then I've got the problem of calling a handler "DidIt()" from a script "RawList" down to the following in a test application:
 
    set myPath to path for script "RawList" extension "scpt"
    display dialog myPath
    tell myPath to DidIt()
 
The dialog properly displays the posix path for the script.  However, when I try to run the handler DidIt() in the last line of the script, I get an error "Can't get DidIt of " followed by the posix path of the script.

Sorry for sounding like I'm completely lost here, but I'll learn.  I promise.  I'm wearing out my Neuberg book on Applescript.


OK, now we're getting somewhere. Thanks for the extra detail.

There are a few hoops to jump through in Studio to do with the fact that conventional AppleScript, inherited from Classic Mac OS  and preserving as much as possible so that scripters don't have to relearn everything they knew before  conflicts with Unix-based stuff inherent in Objective C and bridged to Studio. File-paths are one of those hoops.

You can't tell a POSIX text path to DoIt(). It won't know what you're talking about. You must use the 'load script' command from Standard Additions to load a script file first, and 'load script' takes standard an 'alias' object using colon-file paths. Like this:

    set myPath to path for script "RawList" extension "scpt"
    set colonPathFile  to POSIX file myPath as alias
    set myOtherScript to load script colonPathFile
    tell myOtherScript  to DidIt()

You can store myOtherScript as a script property at the top of your script so all handlers can refer to it, and you don't need to load it more than once. In fact, you'd need to do that if you need to keep track of changing values, since each time you load a script it loads a new copy into memory, and you won't want that. Since Studio script properties are not retained between sessions (i.e. launching the app), the best way to do this, should you need to, would be


property myOtherScript : missing value

on loadOtherScript()
    if myOtherScript is missing value then -- or: if class of myOtherScript  is not script
        set myPath to path for script "RawList" extension "scpt"
        set colonPathFile  to POSIX file myPath as alias
        set myOtherScript to load script colonPathFile
    end if -- if already done once, does nothing
end loadOtherScript



Then, whenever you might need to call the otherScript, just

        my loadOtherScript()
        tell myOtherScript  to DidIt()
       
etc.

That way, it only loads once, and you don't have to worry about which call is made first. Or you can loadOtherScript() from awake from nib handler if you want to get it done right at the beginning.


--
Paul Berkowitz
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Re: Calling handlers in other scripts inside AS application (From: Thomas Berry <email@hidden>)

  • Prev by Date: Re: This Used To Work
  • Next by Date: Modification date checker
  • Previous by thread: Re: Calling handlers in other scripts inside AS application
  • Next by thread: Unknown issue with AS in 10.2
  • Index(es):
    • Date
    • Thread