• 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: How do you get two scripts to communicate?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How do you get two scripts to communicate?


  • Subject: Re: How do you get two scripts to communicate?
  • From: Andrew Oliver <email@hidden>
  • Date: Thu, 01 Jan 2004 15:07:06 -0800

You can't quite do it in the way you describe here - you need to be more
explicit.

The primary issue is that AppleScript doesn't save application references by
name but by application signature. This is how you can write a script that
targets, say, "BBEdit" and it will still work on someone else's machine
whether the actual installed app is called "BBEdit 7", "BBEdit 7.0", or
"BBEdit" - the script is storing a reference to the application's signature
so the name isn't needed.

Unfortunately for you, all AppleScript applications will have the same
signature (unless you've taken steps to use your own application signature),
so your comm.scpt will actually target any (almost random) AppleScript
application on your machine.

There are two solutions. One is to explicitly state the application you want
to target:

set theApp to file "path:to:sayhi.app"
tell application theApp
-- blah blah blah

The second option is to load the script at runtime and target it within your
second script:

set loadedScript to load script "path:to:sayhi.scpt"
set my greet to loadedScript's sayhi("jim")

Personally I prefer the latter form. In both cases, though, you can the
'path to' command to find the current path to a number of standard locations
which can overcome some of the need to use full pathnames.

Andrew
:)

On 1/1/04 1:58 PM, "James Burton" <email@hidden> wrote:

> I read somewhere that one applescript can call another's handler,
> However, I have tried the following:
>
> Script named "sayhi" and saved as an application:
> ----------
> on sayhi(aname)
> set tt to "hi, " & aname
> return tt
> end sayhi
> ----------
>
> a separate Script named "comm.scpt"
>
> ----------
> tell application "sayhi"
> set my greet to sayhi("jim")
> end tell
> return greet
> ----------
>
> The idea is to run comm.scpt, which in turn runs the "sayhi" handler in
> sayhi, and returns the greeting. However, this script ends with an
> error "sayhi got an error: Connection is invalid."
>
> Someone please enlighten me on the proper way to get two applescrpt
> apps to communicate :-)
> _______________________________________________
> 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.
_______________________________________________
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.

  • Follow-Ups:
    • Re: How do you get two scripts to communicate?
      • From: Walter Ian Kaye <email@hidden>
    • Re: How do you get two scripts to communicate?
      • From: Christopher Nebel <email@hidden>
References: 
 >How do you get two scripts to communicate? (From: James Burton <email@hidden>)

  • Prev by Date: How do you get two scripts to communicate?
  • Next by Date: Re: How do you get two scripts to communicate?
  • Previous by thread: How do you get two scripts to communicate?
  • Next by thread: Re: How do you get two scripts to communicate?
  • Index(es):
    • Date
    • Thread